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
Hello, great library, but I've been working on getting an example running inside my App.tsx and I've noticed that for some reason my "exampleJob" will always end with the onFailed event rather than onSuccess.
Here's the code...
// inside App.tsx...let[queue,setQueue]=useState<any>(null);let[queueReady,setQueueReady]=useState(false);constinitQueue=async()=>{if(queue){//// Queue has already been created, just make sure it's running.//queue.start();return;}//// Create the queue.//letq=awaitqueueFactory();//// Add worker for exampleJob.//letjobName="exampleJob";consthandleJob=async(id,payload)=>{console.log(`QueueService::${jobName}Worker::ENTER`,{id, payload});// do nothing for nowconsole.log(`QueueService::${jobName}Worker::EXIT`,{id, payload});};letworkerOptions: WorkerOptions={onComplete: async(id,payload)=>{console.log(`App::Queue::${jobName}::onComplete::${Date.now()}`,{id,payload});},onFailed: async(id,payload)=>{console.log(`App::Queue::${jobName}::onFailed::${Date.now()}`,{id,payload});},onSuccess: async(id,payload)=>{console.log(`App::Queue::${jobName}::onSuccess::${Date.now()}`,{id,payload});},onStart: async(id,payload)=>{console.log(`App::Queue::${jobName}::onStart::${Date.now()}`,{id,payload});},};q.addWorker(jobName,handleJob,workerOptions);//// Start the queue and setState.// q.start();setQueue(q);setQueueReady(true);};/** * Boot the queue. */useEffect(()=>{initQueue();},[]);/** * Run an exampleJob when the queue is ready. */useEffect(()=>{if(!queueReady){// queue not ready, do not proceedreturn;}//// create job//letjobName="exampleJob";letjobData={emailAddress: '[email protected]',randomData: {random: 'object',of: 'arbitrary data'}};letjobOpts: JobOptions={attempts: 1,};queue.createJob(jobName,jobData,jobOpts,true);},[queueReady]);
I've tried to figure out what leads to onFailed vs onSuccess but I haven't had any luck. Appreciate any advice.
The text was updated successfully, but these errors were encountered:
adbalits
changed the title
Job lifecycle always leads to onFailed event?
Job lifecycle always leads to onFailed event (instead of onSuccess)?
Oct 11, 2021
I have done some investigation. The reason the job triggers the onFailed lifecycle event is because this error gets triggered during execution of the job:
TypeError: Cannot read property 'ok' of undefined
at Queue._callee5$ (Queue.js:329)
at tryCatch (runtime.js:63)
at Generator.invoke [as _invoke] (runtime.js:294)
at Generator.next (runtime.js:119)
at fulfilled (Queue.js:10)
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:270
at _callTimer (JSTimers.js:123)
at _callImmediatesPass (JSTimers.js:177)
Update: it was this line in the processJob function of Queue.js that caused the runtime error which led to the onFailed event...
if(!executionResult.ok)thrownewError('Execution failure');// here we catch http errors
I modified my job handler to do the following:
consthandleJob=async(id,payload)=>{console.log(`QueueService::${jobName}Worker::ENTER`,{id, payload});// do nothing for nowconsole.log(`QueueService::${jobName}Worker::EXIT`,{id, payload});return{ok:true};};
And now the onSuccess lifecycle event gets triggered instead of onFailed.
I will leave the issue open because this should really be explained in the README.
Hello, great library, but I've been working on getting an example running inside my App.tsx and I've noticed that for some reason my "exampleJob" will always end with the
onFailed
event rather thanonSuccess
.Here's the code...
And here's the output...
I've tried to figure out what leads to onFailed vs onSuccess but I haven't had any luck. Appreciate any advice.
The text was updated successfully, but these errors were encountered: