-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob.once.js
More file actions
35 lines (28 loc) · 885 Bytes
/
job.once.js
File metadata and controls
35 lines (28 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const Job = require('./job');
/**
* @typedef {object} OnceJobConfig
* @extends {JobConfig}
* @property {boolean} once If set to true will run this job once and only once.
*/
class OnceJob extends Job {
/**
* @param {OnceJobConfig} jobConfig
* @param {JobExecutor} executor
*/
constructor(jobConfig, executor) {
super(jobConfig, executor);
}
run() {
super.run().then(() => this._hasRun = true);
}
/**
* Returns the time (ms) until the next job of this id should run.
* @returns {number}
* @private
*/
get nextRun() {
// TODO POSITIVE_INFINITY will cause setTimeout to be triggered immediately (not a problem right now since this method is called only once, but also not very clean)
return this._hasRun ? Number.POSITIVE_INFINITY : super.nextRun;
}
}
module.exports = OnceJob;