SimonErm/react-native-job-queue

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

projuljustin opened this issue · 9 comments

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

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.

Fixed in latest

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.

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.

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.

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.

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