@fabrix/spool-crons
Version:
Spool - Cron Jobs for Fabrix
98 lines • 3.66 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const extension_1 = require("@fabrix/fabrix/dist/common/spools/extension");
const node_schedule_1 = __importDefault(require("node-schedule"));
const Crons_1 = require("./Crons");
const validator_1 = require("./validator");
const config = __importStar(require("./config/index"));
const pkg = __importStar(require("../package.json"));
const api = __importStar(require("./api/index"));
class CronsSpool extends extension_1.ExtensionSpool {
constructor(app) {
super(app, {
config: config,
pkg: pkg,
api: api
});
this._scheduler = node_schedule_1.default;
this.extensions = {
scheduler: {
get: () => {
return this.scheduler;
},
set: (newScheduler) => {
throw new Error('scheduler can not be set through FabrixApp, check spool-crons instead');
},
enumerable: true,
configurable: true
}
};
}
get scheduler() {
return this._scheduler;
}
validate() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.app.config.get('crons')) {
return Promise.reject(new Error('No configuration found at config.crons!'));
}
return Promise.all([
validator_1.Validator.validateCronsConfig(this.app.config.get('crons'))
])
.catch(err => {
return Promise.reject(err);
});
});
}
configure() {
return __awaiter(this, void 0, void 0, function* () {
return Promise.all([
Crons_1.Crons.configure(this.app),
Crons_1.Crons.copyDefaults(this.app)
])
.catch(err => {
return Promise.reject(err);
});
});
}
initialize() {
return __awaiter(this, void 0, void 0, function* () {
return Promise.all([
Crons_1.Crons.addCrons(this.app)
])
.catch(err => {
return Promise.reject(err);
});
});
}
unload() {
return __awaiter(this, void 0, void 0, function* () {
return Promise.all([
Crons_1.Crons.cancelCrons(this.app)
])
.catch(err => {
return Promise.reject(err);
});
});
}
}
exports.CronsSpool = CronsSpool;
//# sourceMappingURL=CronsSpool.js.map