onQueueFinish returns old values
mival opened this issue · 5 comments
onQueueFinish callback returns empty failed atribute for failed jobs. Calling getJobs after queue finishing returns correct values. Look likes there are some async/timing issues while reading rawJobs value
Am i right that this only occurs if queue.stop() is called?
Hi, we have similar code to this:
queue.configure({
concurrency: 1,
onQueueFinish: async (tasks) => {
// tasks - here missing failed atribute
const jobs = await queue.getJobs();
if (jobs.length > 0) {
const failedJobIds = jobs.map(item => item.failed && item.id);
// here are failed items correct
}
queue.stop();
queue.removeWorker('offlineRequestsQueueWorker', true);
},
});
if (queue.registeredWorkers.offlineRequestsQueueWorker) {
queue.removeWorker('offlineRequestsQueueWorker', true);
}
queue.addWorker(
new Worker('offlineRequestsQueueWorker', async (payload: any) => {
return new Promise((resolve, reject) => {
// some js fetch with resolve / reject
});
}),
);
You don't have call queue.stop() in onQueueFinish, since the queue is already stopped when the callback is called.
The only case i can find where not all finished tasks would be passed to onQueueFinish would be if the queue is stopped by calling queue.stop(). To fix this i have to kind of queue the stop call until the current running jobs finished.
@SimonErm I have a similar issue with the onFailure
worker callback... the failed
field is empty.
I think it's because this line:
react-native-job-queue/src/Queue.ts
Line 330 in c817e6e
is being called before the job has been updated with the proper data
@paulrostorp thank you for the addition, i will take a look at that.