summaryrefslogtreecommitdiff
path: root/src/queue/get-job-info.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/queue/get-job-info.ts')
-rw-r--r--src/queue/get-job-info.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/queue/get-job-info.ts b/src/queue/get-job-info.ts
new file mode 100644
index 0000000000..f601ae62d0
--- /dev/null
+++ b/src/queue/get-job-info.ts
@@ -0,0 +1,15 @@
+import * as Bull from 'bull';
+
+export function getJobInfo(job: Bull.Job, increment = false) {
+ const age = Date.now() - job.timestamp;
+
+ const formated = age > 60000 ? `${Math.floor(age / 1000 / 60)}m`
+ : age > 10000 ? `${Math.floor(age / 1000)}s`
+ : `${age}ms`;
+
+ // 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}`;
+}