How to use the cron.job function in cron

To help you get started, weโ€™ve selected a few 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 sbehrends / Live-WorldCup-Notification-for-Slack / bot.js View on Github external
var announceMatchComplete = function (match) {
    var vs = match.homeTeam + ' vs ' + match.awayTeam;
    var stadium = match.data.c_Stadidum + ', ' + match.data.c_City;
    var text = stopExpression + ' ' + slackLink(vs, match.url) + ' (' + stadium + ')';
    announce(text);
    delete(activeMatches[match.data.n_MatchID]);
};

/**
 * Sends a score summary message to slack.
 */
var announceScore = function (match) {
    announce(match.homeTeam + ' (' + match.score + ') ' + match.awayTeam);
};

var cronJob = cron.job("*/5 * * * * *", function(){


      // Get Match list
      requestify.get('http://live.mobileapp.fifa.com/api/wc/matches').then(function(response) {
            var matches = response.getBody().data.second;

            async.filter(matches, function(item, callback) {
               callback (item.b_Live == true || activeMatches[item.n_MatchID]);

      }, function(results){
          for (var i = 0; i < results.length; i += 1) {
              if (activeMatches[results[i].n_MatchID]) {
                  match = activeMatches[results[i].n_MatchID];
              } else {
                  match = new Match(language);
                  match.on('startMatch', announceMatchStart);
github z1c0 / dashydash / src / components / modules / birthdays / birthdays.js View on Github external
init: function () {
    // each day at 10 AM
    const cronJob = cron.job("0 0 10 * * *", () => {
      sendNotification();
    });
    cronJob.start();
  },
github winderica / KanColleSource / utils / detector.js View on Github external
const cron = require('cron');
const fetch = require('node-fetch');
const { promisify } = require('util');
const fs = require('fs').promises;
const exec = promisify(require('child_process').exec);
const beautify = require('js-beautify').js;
const chunker = require('./chunker');
const searcher = require('./searcher');
const logger = require('./logger');
const jsStyle = require('../style');
const jsonStyle = {
    "indent_size": "2",
    "eol": "\r\n",
};
const detector = cron.job("0 */30 * * * *", async () => {
    try {
        const gameConsts = await (await fetch('http://203.104.209.7/gadget_html5/js/kcs_const.js')).text();
        const version = gameConsts.match(/\d\.\d\.\d\.\d/)[0];
        const currentVersion = await fs.readFile('../version');
        if (version !== currentVersion.toString()) {
            logger.info(`Detected main.js v${version}`);
            const script = await (await fetch(`http://203.104.209.71/kcs2/js/main.js?version=${version}`)).text();
            await fs.writeFile(`../raw.js`, script);
            await fs.writeFile(`../main.js`, beautify(script, jsStyle));
            await fs.writeFile('../version', version);
            const functions = /}\((\[function.*)\).default/s.exec(script)[1];
            chunker(eval(functions)); // haven't find a better way to parse array of functions
            const start = /=\s*(\d*)\)\s*}\(\[/.exec(script)[1];
            await fs.writeFile('../tree.json', beautify(JSON.stringify(searcher(start)), jsonStyle));
            const { stdout, stderr } = await exec(`"../push.sh" "Update: main.js v${version}"`);
            logger.info(stdout);
github z1c0 / dashydash / src / components / modules / pics / pics.js View on Github external
init : function() {
    // every hour
    var cronJob = cron.job("0 0 */1 * * *", function() {
      checkForNewPhotos(config);
    });
    cronJob.start();
    checkForNewPhotos(config);
  },
github alexolivero / Obscurify / report_generator.js View on Github external
var cron = require('cron');

//run this cron task every 2 hours
var cronJob = cron.job("0 */2 * * *", function(){

  const MongoClient = require('mongodb').MongoClient;
  var countries = {}; // a country looks like:
  // key -> country code, ex. "US"
  // breakdown : [ { score of x : amount of users getting that score }, { } , ...]
  // averageScore : 180
  // userCount : 15,000
  // audioFeatureAverages : audioFeatureAverages

  var globalAverageScore = 0;
  var globalUserCount = 0;

  generateReport();

  async function generateReport() {
    try{
github z1c0 / dashydash / src / components / modules / movies / movies.js View on Github external
init: function () {
    if (secrets.iftttkey) {
      const cronJob = cron.job("0 0 */1 * * *", () => {
        checkMovies();
      });
      cronJob.start();
      checkMovies();
    }
  }
}

cron

Cron jobs for your node

MIT
Latest version published 4 months ago

Package Health Score

94 / 100
Full package analysis