-
Notifications
You must be signed in to change notification settings - Fork 638
Closed
Description
Right now I have this:
'use strict';
//dts
import {CDTChronJobItem} from "../../index";
//core
import cp = require('child_process');
import path = require('path');
import fs = require('fs');
// npm
const {CronJob} = require('cron');
/////////////////////////////////////////////////////////////////////////
export const run = function (v: CDTChronJobItem, projectRoot: string) {
const id = v.id;
const schedule = v.schedule;
const onStart = function () {
console.log(`job with id="${id}" has started.`);
const shp = path.resolve(projectRoot + '/lib/shell-scripts/mongo-restore.sh');
const k = cp.spawn('bash');
k.stdin.write(fs.createReadStream(shp));
k.once('exit', function () {
k.unref();
});
};
const onStop = function () {
console.log(`job with id="${id}" has stopped.`);
};
return new CronJob(
schedule,
onStart,
onStop,
false, // don't start the job just yet
'America/Los_Angeles'
);
};it would be interesting if the chron job could only start once the previous one had completed.
the right way to do that, would be to use something like async-queue, and my onStart function would have to take a callback.
Is it possible to do that with node-chron? Just curious.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels