SGrondin / bottleneck

Job scheduler and rate limiter, supports Clustering
MIT License
1.83k stars 78 forks source link

dynamic schedule / retry #213

Closed RichardWright closed 1 year ago

RichardWright commented 1 year ago

Hi

Is it possible to pass in custom meta data when scheduling a job? This would allow me to decide if a retry should be attempted or not, allowing it to be set when scheduling gives control back to the callee.

response = await rateLimiter.schedule( { retry: false, //this is a custom piece of meta data expiration: 15000, }, () => fetch(requestWithHeaders, requestOptions) );

` rateLimiter.on('failed', async (error, jobInfo) => {

  logger.error(`FAILED: ${JSON.stringify(jobInfo)}`);

 if(jobInfo.retry) {
   if (jobInfo.retryCount < retries - 1) {
     logger.debug(`Retrying job ${id} in ${retriesIntervalMilliseconds}ms!`);

    return retriesIntervalMilliseconds;
  }

}
}); `

RichardWright commented 1 year ago

Or retry count is added as an advanced option -

https://www.npmjs.com/package/bottleneck#job-options

RichardWright commented 1 year ago

Would adding options to this line - https://github.com/SGrondin/bottleneck/blob/master/lib/Bottleneck.js#L543 enable this?

RichardWright commented 1 year ago

Closing