SimonErm/react-native-job-queue

Async function call doesn't run in Worker

therealtgd opened this issue · 1 comments

When there is no internet connection in my app I want to enable the user to make changes, optimistically save them in a MobX store, and add a request to save the changes on the server to the queue. Then when the user is back online I want to trigger the queue to run the requests, which I was able to do by using react-native-community/netinfo, by listening to network connection change and using queue.start() when the connection is re-established. But the request doesn't run, and nothing gets logged to the console from the onStart function.

I provided the queue code below. What am I doing wrong?

import queue, { Worker } from 'react-native-job-queue';

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

queue.addWorker(
  new Worker('request-worker'),
  async (request) => await request(),
  {
    onStart: async (id) => {
      console.log(`Job ${id} has started processing.`);
    },
  },

);

export default queue;

Below is an example of how I add a job.

const request = async () => await APIManager.get('some_url')
queue.addJob('request-worker', request, {}, false);

Hello @therealtgd,
The problem is that you try to pass a function as job payload, but that is not possible (#22).
Instead you should pass the request payload as job payload and implement the request as the worker.