You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a typescript application running through BUN that should perform some long jobs submitted by the user with BullMQ for job scheduling.
When I try to use the sandboxed processor, the job never reaches the completed state, although the processor code has finished and returned a value or thrown an exception.
The problem disappears if I remove any "await" statement from my processor code or the "async" from the function.
Furthermore, the producer code (file queue.ts in my example below) does not exit if I do not add "await queue.disconnect();" at the end.
I added all event handlers and didn't notice any errors, but the completed handler is never called, and the process remains stuck (no other jobs can be processed) until I close it manually with CTRL + C
How to reproduce.
In my code, I have a queue.ts file to submit test jobs:
import{Queue}from"bullmq";constqueue=newQueue("jobs",{connection: {host: (process.env.REDIS_HOSTasstring)??"localhost",port: parseInt((process.env.REDIS_PORTasstring)??"6379"),username: process.env.REDIS_USERasstring,password: process.env.REDIS_PASSasstring,},defaultJobOptions: {attempts: 3,removeOnComplete: process.env.NODE_ENV!=="development",removeOnFail: process.env.NODE_ENV!=="development",}});exportdefaultqueue;awaitqueue.add("job1",{name: "Job 1"});awaitqueue.add("job2",{name: "Job 2"});awaitqueue.add("job3",{name: "Job 3"});awaitqueue.disconnect();// I had to manually disconnect otherwise this code will not exit
a worker.ts file to run the worker
import{Job,Worker}from"bullmq";importpathfrom"path";constprocessorPath=path.join(__dirname,"processor.ts");constworker=newWorker("job",processorPath,{connection: {host: (process.env.REDIS_HOSTasstring)??"localhost",port: parseInt((process.env.REDIS_PORTasstring)??"6379"),username: process.env.REDIS_USERasstring,password: process.env.REDIS_PASSasstring,},autorun: true,skipStalledCheck: true,concurrency: 5,});worker.on("error",(error)=>{console.error(error);});worker.on("active",(job,prev)=>{console.log(`Job ${job.id} active from ${prev}`);});worker.on("completed",(job: Job,returnValue: any)=>{console.log(`Job ${job.id} completed with return value: ${returnValue}`);});worker.on("failed",(job: Job|undefined,error: Error)=>{console.error(`Job ${job?.id} failed with error: ${error}`);});worker.on("progress",(job: Job,progress: number|object)=>{console.log(`Job ${job.id} is ${progress}% done`);});constgracefulShutdown=async(signal: string)=>{console.log(`Received ${signal}, closing worker...`);awaitworker.close();process.exit(0);};process.on("SIGINT",()=>gracefulShutdown("SIGINT"));process.on("SIGTERM",()=>gracefulShutdown("SIGTERM"));
and a processor.ts file
import{SandboxedJob}from"bullmq";exportdefaultasyncfunctionprocessor(job: SandboxedJob){job.log("Start processing job");awaitjob.updateProgress(100);console.log("Doing something...",job.id);// sleep for 5 secondsawaitnewPromise((resolve)=>setTimeout(resolve,5000));return"Job completed!";}
I run the script using bun queue.tsand bun worker.ts in two shells.
Relevant log output
> bun worker.ts
Job 178 active from waiting
Job 179 active from waiting
Job 180 active from waiting
Job 179 is 100% done
Job 180 is 100% done
Job 178 is 100% done<-------------- The completed handler never executes, and the code does not exituntil I close it manually with CTRL + C
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Version
v5.7.4
Platform
NodeJS
What happened?
Hi,
I have a typescript application running through BUN that should perform some long jobs submitted by the user with BullMQ for job scheduling.
When I try to use the sandboxed processor, the job never reaches the completed state, although the processor code has finished and returned a value or thrown an exception.
The problem disappears if I remove any "await" statement from my processor code or the "async" from the function.
Furthermore, the producer code (file queue.ts in my example below) does not exit if I do not add "await queue.disconnect();" at the end.
I added all event handlers and didn't notice any errors, but the completed handler is never called, and the process remains stuck (no other jobs can be processed) until I close it manually with CTRL + C
How to reproduce.
In my code, I have a
queue.ts
file to submit test jobs:a
worker.ts
file to run the workerand a
processor.ts
fileI run the script using
bun queue.ts
andbun worker.ts
in two shells.Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: