react-native-job-queue icon indicating copy to clipboard operation
react-native-job-queue copied to clipboard

Requeue job method does not seem to work.

Open e-munir-m opened this issue 2 years ago • 7 comments

e-munir-m avatar Dec 07 '22 13:12 e-munir-m

Can you provide some more information(which plattfrom, which RN-Version) and code to reproduce the issue?

SimonErm avatar Dec 14 '22 20:12 SimonErm

I am on RN version 0.67.4 using the latest version of the package available developing on iOS. An example piece of code is: queue.getJobs().then(jobs => { jobs.map(async job => { job.priority += 1; queue.requeue(job); }); })

e-munir-m avatar Dec 15 '22 11:12 e-munir-m

Have you configure max attempts for the worker? By default the will just run once, so you would have to reset job.metaData by setting job.metaData=JSON.stringify({ failedAttempts: 0, errors: [] }) for example. I think failedAttempts should live in the meta data and requeue should do the reset, i will refactor this next year.

Furthermore you should filter out active jobs before requeuing them.

SimonErm avatar Dec 20 '22 20:12 SimonErm

The issue I'm running into with requeueJob is that I get job.payload as an object in the onFailure callback, but when I try to requeueJob it, I get "Value for payload cannot be cast from ReadableNativeMap to String":

Screen Shot 2023-01-10 at 14 04 39

When I queue.requeueJob({...job, payload: JSON.stringify(job.payload)}) (which seems inconsistent), it does not error out, but it never creates a job, either.

spsaucier avatar Jan 10 '23 03:01 spsaucier

The above is for Android, specifically. I have not tried on iOS.

spsaucier avatar Jan 12 '23 23:01 spsaucier

queue.requeueJob({...job, payload: JSON.stringify(job.payload)}) that's the way it's done internally too, but you are right that's inconvinient and inconsistent. I have to refactor this too.

Have you configure max attempts for the worker? By default the will just run once, so you would have to reset job.metaData by setting job.metaData=JSON.stringify({ failedAttempts: 0, errors: [] }) for example. I think failedAttempts should live in the meta data and requeue should do the reset, i will refactor this next year.

Furthermore you should filter out active jobs before requeuing them.

Can you try this like queue.requeueJob({...job, payload: JSON.stringify(job.payload),metaData:JSON.stringify({ failedAttempts: 0, errors: [] })})

SimonErm avatar Jan 16 '23 21:01 SimonErm

This does not work either.

spsaucier avatar Oct 03 '23 23:10 spsaucier