SimonErm/react-native-job-queue

Requeue job method does not seem to work.

e-munir-m opened this issue · 7 comments

Requeue job method does not seem to work.

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

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); }); })

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.

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.

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

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: [] })})

This does not work either.