SimonErm / react-native-job-queue

Easy to use react-native queuing library
https://simonerm.github.io/react-native-job-queue/
122 stars 33 forks source link

getJobs returns no jobs, but downloading the database shows four jobs #42

Closed projuljustin closed 3 years ago

projuljustin commented 3 years ago

For some reason if I run getJobs (to check for any that are stuck in active or failed and need to be processed) it returns no jobs. However if I download the database from the phone it shows I have four failed jobs.

testJobProcess = async () => {
    queue.configure({
      onQueueFinish: (executedJobs) => {
        //console.log('Queue stopped and executed');
      }
    });

    var registeredWorkers = queue.registeredWorkers;

    if (!registeredWorkers.testJobType) {
      queue.addWorker(new Worker('testJobType', async (data) => {
        console.log(`Executing job with data: ${JSON.stringify(data)}`);

        var jobs = await queue.getJobs();
        console.log(`createManageQueueJob jobs.length: ${jobs.length}`);

        await new Promise((resolve) => {
          setTimeout(() => {
            console.log('"testJobType" has completed!');
            resolve();
          }, 45000);
        });
      }));
    }

    queue.addJob('testJobType', {
      priority: 1, 
    }, {
      timeout: 240000, 
      atempts: 5 
    });
  }

image

image

SimonErm commented 3 years ago

The current query which is executed on getJobs is this: SELECT * FROM job WHERE active == 0 AND failed == '' ORDER BY priority DESC,datetime(created) I can't remember what my intention was to ignore the failed jobs, but your expectation is right the getJobs method should return all jobs. I will fix this.

SimonErm commented 3 years ago

https://github.com/SimonErm/react-native-job-queue/pull/43

SimonErm commented 3 years ago

Fixed in latest

projuljustin commented 3 years ago

Awesome, thanks @SimonErm!

Question, is there any way to re-process those failed jobs? My plan was to run getJobs, then for each job that is not active and failed I would throw it back in the queue. I was doing that with react-native-queue but wanted to swap over to your library as you've been maintaining it. However there doesn't appear to be a way exposed for me to do this? Do I have to create a new job? It would be ideal if I could use the saved jobs for this re-process logic.

SimonErm commented 3 years ago

Currently the only way to retry the failed job is to create a new job with the same payload. But now that all jobs are returned, I realized that the failed jobs will stay in the queue forever unless there is a public method to retry or remove them. I will look into this over the weekend.

SimonErm commented 3 years ago

44

projuljustin commented 3 years ago

I appreciate you looking into this. I'm really excited to have my photo upload process run in the context of workers and jobs. I can keep track of upload status separately and create new jobs to reprocess failed jobs, but it seems like it would be better to just use chained jobs and retry the failed job when it fails.

However after this last update, it seems like when I force close and open the app, the jobs that were active are now gone? The only jobs that remain after mount are the failed jobs. This was working before the last update, as I would open the app again and the previously active jobs would automatically get thrown on the queue. I can open a new issue if needed.

SimonErm commented 3 years ago

However after this last update, it seems like when I force close and open the app, the jobs that were active are now gone? The only jobs that remain after mount are the failed jobs

Which was the last running version? 0.3.0 or a previous one?

I can open a new issue if needed.

Yes, please open a new issue.

projuljustin commented 3 years ago

I was on 0.2.7, I'll create a new issue