Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async restore() {
- debug('restore');
- try {
- if (fs.existsSync(process.env.PERSISTENCE_FILE)) {
- debug('File exists at ', process.env.PERSISTENCE_FILE);
- // tasks = {}
- this.tasks = JSON.parse(fs.readFileSync(process.env.PERSISTENCE_FILE));
- debug('persistance file is Loaded\n', 'TASKS ARRAY\n', this.tasks);
- // task = {
- // id: TASK,
- // id: TASK
- // }
- } else debug('No persistance file at', process.env.PERSISTENCE_FILE);
- } catch (err) {
- console.error(err);
- process.exit(2);
- }
- for (const id in this.tasks) {
- if (this.tasks.hasOwnProperty(id)) {
- // rehydrate
- debug('Before Rehydration');
- this.tasks[id] = new TASK(this.tasks[id].taskData, () => {
- // replicate the done
- }, this.tasks[id]);
- debug('After Rehydration');
- // * the bellow is equivalent of -> this._handler = new DOCKER(this); etc.
- this.tasks[id].initHandler();
- debug('HANDLER -> ', this.tasks[id]._handler);
- try {
- await this.tasks[id]._handler.reloadState();
- debug('Reattached to Task' /* this.tasks[id]._handler.container.id */);
- } catch (err) {
- console.log(err);
- // TODO restart job
- }
- }
- }
- // TODO: Uncomment save() callback
- this.saveTimer = setInterval(() => {
- debug('Calling save()');
- for (const id in this.tasks) {
- if (moment().isAfter(this.tasks[id].finishTime)) clearInterval(this.saveTimer);
- }
- this.save();
- }, 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement