Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding jobs using Koa + BullBoard #841

Closed
tim-trewartha opened this issue Oct 23, 2024 · 6 comments
Closed

Error when adding jobs using Koa + BullBoard #841

tim-trewartha opened this issue Oct 23, 2024 · 6 comments

Comments

@tim-trewartha
Copy link

tim-trewartha commented Oct 23, 2024

Hi! We are using BullBoard and it is definitely a useful tool, but we are hitting an issue when adding jobs using the UI. We get this error response and a 500:

{
    "error": "Internal server error",
    "message": "Cannot destructure property 'name' of 'req.body' as it is undefined.",
    "details": "TypeError: Cannot destructure property 'name' of 'req.body' as it is undefined.\n    at addJob (/app/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@bull-board/api/src/handlers/addJob.ts:10:11)\n    at Object.handler (/app/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@bull-board/api/src/providers/queue.ts:33:12)\n    at <anonymous> (/app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/@bull-board/koa/src/KoaAdapter.ts:134:40)\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:42:32)\n    at /app/node_modules/.pnpm/[email protected]/node_modules/koa-router/lib/router.js:372:16\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:42:32)\n    at /app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:34:12\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-router/lib/router.js:377:31)\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:42:32)\n    at /app/node_modules/.pnpm/[email protected]/node_modules/koa-mount/index.js:52:32\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:42:32)\n    at views (/app/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/koa-views/src/index.js:91:12)\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:42:32)\n    at <anonymous> (/app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/@bull-board/koa/src/KoaAdapter.ts:96:15)\n    at dispatch (/app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:42:32)\n    at /app/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:34:12"
}

Our setup looks more or less like this:

import { createBullBoard } from '@bull-board/api';
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
import { KoaAdapter } from '@bull-board/koa';
import { Queue, type ConnectionOptions } from 'bullmq';
import bodyParser from 'koa-bodyparser';
import type Koa from 'koa';

import { startKoaServer, type StartupFunctionConfig } from '@shared/koa-utils';


const redisConnectionSettings: ConnectionOptions = {
    ....
};

const allQueueNames = [
    'example-queue'
];

function setupKoaServer<Context extends Koa.ParameterizedContext>({
    application,
    router,
}: StartupFunctionConfig<Context>): Koa {
    const serverAdapter = new KoaAdapter();

    const allQueueAdapters = allQueueNames.map(
        (x) =>
            new BullMQAdapter(
                new Queue(x, {
                    connection: redisConnectionSettings,
                })
            )
    );

    createBullBoard({
        queues: allQueueAdapters,
        serverAdapter,
        options: {
            uiConfig: {
                boardTitle: 'BullMQ Dash',
            },
        },
    });

    serverAdapter.setBasePath('/ui');
    application
        .use(bodyParser())
        .use(serverAdapter.registerPlugin())
        .use(router.routes())
        .use(router.allowedMethods());

    return application;
}

// This is a lightweight re-usable function which we use in multiple services 
void startKoaServer('bullboard', {
    koaSetupFunction: setupKoaServer,
    logger: defaultLogger,
    port: settings.port,
});

Thanks for any pointers! for some reason adding the body parser is not sufficient and am not sure what we are missing

@felixmosh
Copy link
Owner

Hi, thank you for reporting this issue.
Do you see the job name in the network tab?

@tim-trewartha
Copy link
Author

Hi! Yup I do see the data:

CURL:

curl 'https://bull-board-local.test.com/ui/api/queues/example/add' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'content-type: application/json' \ \
  -H 'priority: u=1, i' \
  -H 'sec-ch-ua: "Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36' \
  --data-raw '{"name":"PollConsentStatus","data":{"a":"b"},"options":{}}'

image

@felixmosh
Copy link
Owner

felixmosh commented Oct 23, 2024

Ok, so it probably get lost in KoaAdapter somewhere...

I'm able to reproduce it... will look at it soon

@felixmosh
Copy link
Owner

Can you confirm that v6.3.0 solves this issue for you?

@tim-trewartha
Copy link
Author

Yup! appears to be working now - thanks so much!

@Jaywaa
Copy link

Jaywaa commented Oct 24, 2024

Thanks for fixing @felixmosh! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants