LoginSignup
1
0

More than 3 years have passed since last update.

Node.jsのジョブキューbull使用感メモ

Posted at

github: https://github.com/OptimalBits/bull
npm: https://www.npmjs.com/package/bull

リトライ

デフォルトではリトライしない。
queueに対してではなく、jobをaddするときにオプションでattempsやbackoffを指定する。
https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueadd

Backoffはfixed(固定)の他にexponentialもある。

failedイベント はリトライの度に発火するので、
たとえばattempsを5としてずっと失敗すると5回走る。

今何回目のリトライなのかは job.attemptsMade で取得できる。
最終的に失敗したかどうかをハンドルする方法がわからない。
completedイベント は成功のときにしか発火しなかった。
errorイベント は全く発火しなかった。
以下のように試行回数を比較すれば一応できる。

queue.on('failed', job => {
    logger.debug(`job[${job.id}] failed ${job.attemptsMade} times`)
    if (job.attemptsMade === job.opts.attempts) {
        logger.error(`finally, failed job[[${job.id}]]`)
    }
})
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0