mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
* upgrade gulp-babel * upgrade babel-eslint * upgrade eslint-friendly-formatter * start upgrading chai * start to upgrade eslint * restore skipped tests * start to upgrqde monk * fix linting and remove unused file * fix mocha notifications, and common tests * fix unit tests * start to fix initrgration tests * more integration tests fixes * upgrade monk to latest version * lint /scripts * migrations: start moving to /archive unused migrations and run eslint with --fix * lint migrations * fix more integration tests * fix test
45 lines
1007 B
JavaScript
45 lines
1007 B
JavaScript
'use strict';
|
|
|
|
let logger = require('./logger');
|
|
|
|
class Timer {
|
|
constructor (options) {
|
|
options = options || {};
|
|
let warningThreshold = options.minutesWarningThreshold || 10;
|
|
|
|
this.count = 0;
|
|
this._minutesWarningThreshold = warningThreshold * 60;
|
|
|
|
if (!options.disableAutoStart) this.start();
|
|
}
|
|
start () {
|
|
this._internalTimer = setInterval(() => {
|
|
this.count++;
|
|
|
|
let shouldWarn = this._minutesWarningThreshold < this.count;
|
|
let logStyle = shouldWarn ? 'error' : 'warn';
|
|
let dangerMessage = shouldWarn ? 'DANGER: ' : '';
|
|
|
|
if (this.count % 30 === 0) {
|
|
logger[logStyle](`${dangerMessage}Process has been running for`, this.count / 60, 'minutes');
|
|
}
|
|
}, 1000);
|
|
}
|
|
stop () {
|
|
if (!this._internalTimer) {
|
|
throw new Error('Timer has not started');
|
|
}
|
|
clearInterval(this._internalTimer);
|
|
}
|
|
|
|
get seconds () {
|
|
return this.count;
|
|
}
|
|
|
|
get minutes () {
|
|
return this.count / 60;
|
|
}
|
|
}
|
|
|
|
module.exports = Timer;
|