bullmq
bullmq copied to clipboard
[Bug]: Upserting a job scheduler while it is still running results in a strange job
Version
v5.46.1
Platform
NodeJS
What happened?
I am having a strange error since I updated BullMQ from version 5.44 to 5.46.
I can see from my logs that the jobs inside the callback from worker.on("active", callback) have the name property set to undefined.
This was not true for all jobs, just for one created by the upsertJobScheduler() method.
I can run getJobs() on the queue and what I see is the following:
...
name: undefined,
data: {},
opts: {
attempts: 0,
backoff: undefined,
},
id: "repeat:foo:1743775453000",
progress: 0,
returnvalue: null,
stacktrace: [],
delay: NaN,
priority: NaN,
attemptsStarted: 1,
attemptsMade: 1,
repeatJobKey: undefined,
timestamp: NaN,
parentKey: undefined,
parent: undefined,
debounceId: undefined,
deduplicationId: undefined,
...
So I tried to reproduce it, and I did it with the following code.
How to reproduce.
export const sleep = (ms: number) =>
new Promise<void>((res) => {
setTimeout(() => {
res();
}, ms);
});
const connection = new Redis("localhost", {
maxRetriesPerRequest: null,
enableOfflineQueue: false,
});
const queue = new Queue("test", {
connection,
defaultJobOptions: {
removeOnComplete: true,
},
});
const worker = new Worker(
"test",
async (job) => {
console.log(
`processing ${job.name} with data: ${JSON.stringify(job.data)}`,
);
await sleep(2000);
console.log(job.opts);
},
{ connection, concurrency: 5 },
);
await queue.upsertJobScheduler(
"foo",
{ every: 1000 },
{
name: "bruh",
data: { hello: "world" },
},
);
await sleep(1000);
console.log(await queue.removeJobScheduler("foo"));
await queue.upsertJobScheduler(
"foo",
{ every: 1000 },
{
name: "bruh",
data: { something: "else" },
},
);
Relevant log output
> bun run bullmq.ts
processing bruh with data: {"something":"else"}
{
attempts: 0,
repeat: {
every: 1000,
count: 4,
offset: 588,
},
delay: 984,
jobId: "repeat:foo:1743775493000",
removeOnComplete: true,
prevMillis: 1743775493000,
timestamp: 1743775492604,
backoff: undefined,
}
processing bruh with data: {"hello":"world"}
{
attempts: 0,
repeat: {
count: 1,
offset: 51,
every: 1000,
},
jobId: "repeat:foo:1743775516000",
delay: 0,
timestamp: 1743775516052,
prevMillis: 1743775516000,
removeOnComplete: true,
backoff: undefined,
}
true
processing bruh with data: {"hello":"world"}
{
attempts: 0,
repeat: {
count: 2,
offset: 51,
every: 1000,
},
jobId: "repeat:foo:1743775517000",
delay: 993,
timestamp: 1743775516058,
prevMillis: 1743775517000,
removeOnComplete: true,
backoff: undefined,
}
processing bruh with data: {"something":"else"}
{
attempts: 0,
repeat: {
count: 1,
offset: 70,
every: 1000,
},
jobId: "repeat:foo:1743775517000",
delay: 0,
timestamp: 1743775517070,
prevMillis: 1743775517000,
removeOnComplete: true,
backoff: undefined,
}
1070 | }
1071 | }
1072 | finishedErrors({ code, jobId, parentKey, command, state, }) {
1073 | switch (code) {
1074 | case enums_1.ErrorCode.JobNotExist:
1075 | return new Error(`Missing key for job ${jobId}. ${command}`);
^
error: Missing key for job repeat:foo:1743775517000. moveToFinished
at finishedErrors (/home/andrea/projects/inkofpixel/ysms-utils/node_modules/bullmq/dist/cjs/classes/scripts.js:1075:24)
at <anonymous> (/home/andrea/projects/inkofpixel/ysms-utils/node_modules/bullmq/dist/cjs/classes/scripts.js:434:24)
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Please note that the error is raised when the job is already in the queue (you may need to run the script twice)
pr was merged, pls if you still see this issue feel free to reopen it or create a new issue