Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
create : function (req,res) {
// Validate cron
if(!cron.validate(req.body.cron)) {
return res.badRequest({
message : "Cron parameters are not valid",
fields : ["cron"]
});
}
// Check if another schedule using the defined
// connection already exists.
sails.models.snapshotschedule.find({
connection : req.body.connection
}).exec(function(err,results){
if(err) {
return res.negotiate(err);
}
if(results && results.length > 0) {
exports.createNodeJob = async function (node, crontime, settings) {
console.log("Creating cron")
if(cron.validate(crontime)) {
await db.collection("gp_cron").insert({"node": node, "crontime": crontime, "settings": settings});
return {node: node, cron: cron, settings: settings}
} else {
throw("Invalid cron expression")
}
}
input.jobs.forEach((job: any) => {
if (!isFunction(job.fn)) {
errors.push(error("job.fn", "a funciton", job.fn));
}
if (!cron.validate(job.schedule)) {
errors.push(
error("job.schedule", "a valid cron expression", job.schedule)
);
}
});
}
export function parseCron(interval) {
try {
if (!interval) throw new Error('Interval not found');
const parsed = parseInt(interval);
if (!parsed || typeof parsed !== 'number')
throw new Error('Interval not valid');
if (parsed < 60) throw new Error('Interval too low');
if (parsed >= 84600) throw new Error('Interval too high');
const minutes = parseInt(parsed / 60);
const cronstr = `0 */${minutes} * * * *`;
if (!cron.validate(cronstr))
throw new Error(
'Generated cron expression not valid for node-cron module'
);
log('cron:parse-interval', `Using the next interval: ${cronstr}`, 'debug');
return cronstr;
} catch (error) {
log(
'cron:parse-interval',
`Using default value due to: ${error.message || error}`
);
return '0 1 * * * *';
}
}