Steve Jobs: The Simple Jobs Queue That Just Works

The package already wraps all the code in try/catch, and if there is an error somewhere it will mark the job as failed, which means it will retry on next server restart.

so this would work:

var data = myFunction()
this.success(data)

but something like this would not:

return myFunction()
1 Like

Sorry I misexplained myself, Iā€™d like the job to be reschedule at a later time in case it fails, not only at server restart.

My function depend on an API which is sometimes down, but when a job fails because of the down API all the jobs are then blocked until a server restart which is not practical at all. Iā€™d like for a job to reschedule 1hour later in case it fails.

What you are trying to is very easy - I suggest you get familiar with the documentation and API :slight_smile:

I do know I have to use the this.reschedule, I just do not know how to catch the error in case the api I am calling (binance cryptoexchange) is down and then use the reschedule in this case. I was thiking to use a try catch but you said Steve Jobs was already using one and I am not sure it is good chaining them. right ow it works like this :

  • shedule a jobs a defined time
  • when time comes, calls the binance API to get relevant data
  • use data for calculations
  • update my database with needed data
  • run this.success() to close the job.

But sometimes the API I am calling is down and I would like :

  • shedule a jobs a defined time
  • when time comes, calls the binance API to get relevant data
  • if Binance API is down : run this.reschedule(in 2 hours)
  • else:
  • use data for calculations
  • update my database with needed data
  • run this.success() to close the job.

try / catch should not be used here because I do not think the API request will throw a code exception if it fails. You need to see the statusCode of the call, or something else, to determine if it was successful. Then you wrap that in an if/else statement and deal with the job appropriately.

1 Like