How to use the node-cron.validate function in node-cron

To help you get started, we’ve selected a few node-cron examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pantsel / konga / api / controllers / SnapshotScheduleController.js View on Github external
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) {
github GLAMpipe / GLAMpipe / app / cron.js View on Github external
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")
	}
}
github pascalw / dashbling / src / lib / clientConfig.ts View on Github external
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)
        );
      }
    });
  }
github wazuh / wazuh-kibana-app / server / lib / parse-cron.js View on Github external
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 * * * *';
  }
}

node-cron

A simple cron-like task scheduler for Node.js

ISC
Latest version published 1 year ago

Package Health Score

71 / 100
Full package analysis

Popular node-cron functions