UNPKG

718 BJavaScriptView Raw
1/**
2 * @copyright Copyright (c) 2019 Maxim Khorin <maksimovichu@gmail.com>
3 */
4'use strict';
5
6const Base = require('../base/Base');
7
8module.exports = class Job extends Base {
9
10 isCanceled () {
11 return this._canceled;
12 }
13
14 async run () {
15 // place code here
16 }
17
18 cancel () {
19 this._canceled = true;
20 }
21
22 async execute () {
23 if (this._started) {
24 throw new Error('Job has already started');
25 }
26 this._started = true;
27 await PromiseHelper.setImmediate();
28 await this.run();
29 }
30
31 log () {
32 this.task.log(...arguments);
33 }
34};
35
36const PromiseHelper = require('../helper/PromiseHelper');
\No newline at end of file