APの統計とログの修正と強化 (#5585)

* Fix #5580

* Improve AP logging
This commit is contained in:
MeiMei
2019-11-07 00:02:18 +09:00
committed by syuilo
parent 8bdd4fd061
commit 873444c3c6
4 changed files with 45 additions and 41 deletions

15
src/queue/get-job-info.ts Normal file
View File

@@ -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}`;
}