2023-01-12 21:40:33 -07:00
|
|
|
import type Bull from "bull";
|
2019-11-06 08:02:18 -07:00
|
|
|
|
|
|
|
export function getJobInfo(job: Bull.Job, increment = false) {
|
|
|
|
const age = Date.now() - job.timestamp;
|
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
const formated =
|
|
|
|
age > 60000
|
|
|
|
? `${Math.floor(age / 1000 / 60)}m`
|
|
|
|
: age > 10000
|
|
|
|
? `${Math.floor(age / 1000)}s`
|
|
|
|
: `${age}ms`;
|
2019-11-06 08:02:18 -07:00
|
|
|
|
|
|
|
// onActiveとかonCompletedのattemptsMadeがなぜか0始まりなのでインクリメントする
|
|
|
|
const currentAttempts = job.attemptsMade + (increment ? 1 : 0);
|
|
|
|
const maxAttempts = job.opts ? job.opts.attempts : 0;
|
|
|
|
|
|
|
|
return `id=${job.id} attempts=${currentAttempts}/${maxAttempts} age=${formated}`;
|
|
|
|
}
|