How to use the node-schedule.scheduleJob function in node-schedule

To help you get started, we’ve selected a few node-schedule 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 punchcard-cms / punchcard / lib / schedule / utils.js View on Github external
return new Promise(res => {
    if (down) {
      if (moment(revision.sunset).unix() <= now) {
        pull(revision).catch(e => {
          // Need to message out here as we can't properly reject Promises
          console.error(`Sunset failed: ${e.message}`); // eslint-disable-line no-console
        });
      }
      else {
        scheduler.scheduleJob(down, () => {
          pull(revision).catch(e => {
            // Need to message out here as we can't properly reject Promises
            console.error(`Sunset failed: ${e.message}`); // eslint-disable-line no-console
          });
        });
      }
    }

    res(true);
  });
};
github hasura / issues / app / src / server.js View on Github external
// Listen at the server
if (config.port) {
  server.listen(config.port, config.host, (err) => {
    if (err) {
      console.error(err);
    }
    console.info('----\n==> ✅  %s is running, talking to API server.', config.app.title);
    console.info('==> 💻  Open http://%s:%s in a browser to view the app.', config.host, config.port);
  });
} else {
  console.error('==>     ERROR: No PORT environment variable has been specified');
}

// Schedule the emails to be sent out
schedule.scheduleJob(EMAIL_CRON, () => {
  console.log('\nRUNNING JOB:');
  if (ACTIVE_MILESTONE) {
    fetch(`${INTERNAL_ENDPOINT}/email-screenshot/${ACTIVE_MILESTONE}`).then(response => {
      console.log('Made request to send sprint email');
      if (response.status >= 200 && response.status < 300) {
        console.log('successfull');
        response.text().then(d => (console.log(d)));
      } else {
        console.error('fail');
        response.text().then(d => (console.error(d)));
      }
    });
  } else {
    fetch(`${INTERNAL_ENDPOINT}/email/maintenance`).then(response => {
      console.log('Made request to send maintenance email');
      if (response.status >= 200 && response.status < 300) {
github superman66 / wakatime-sync / src / index.ts View on Github external
if (error.response) {
        const { data } = error.response
        console.log(`${date}: 糟糕....请求出了点小差错。错误原因:${JSON.stringify(data)}`)
        serverPushInstance.sendMessageToWechat(
          `【Wakatime Sync】${date}的数据同步失败`,
          `错误原因:${JSON.stringify(data)}`
        )
      }
    })
}

// 每次重跑 job 手动执行一次同步
syncWakaTimeToGist(config.syncGistId)

// 每天1点30分30秒执行该job
const job = schedule.scheduleJob('30 30 1 * * *', function() {
  syncWakaTimeToGist(config.syncGistId)
})
github surmon-china / nodepress / src / todos / np-redis.js View on Github external
})
    })())
  }

  // 定时任务
  if (timing) {
    const promiseTask = () => {
      promise()
        .then(data => hommizationSet(key, data))
        .catch(err => {
          console.warn(`Redis 定时任务执行失败,${timing.error} 后重试:`, err)
          setTimeout(promiseTask, timing.error)
        })
    }
    promiseTask()
    schedule.scheduleJob(timing.schedule, promiseTask)
  }
  
  // 返回 Redis 获取器
  return () => hommizationGet(key)
}
github alexanderepstein / Sandman / js / indexandpref.js View on Github external
function nodeJobs(sleepTimes) {
  for (i = 0; i < 6; i++) {
    try {
      if (jobs[i] != null)
      {
      jobs[i].cancel(); //try to cancel respective job
    }
    } catch (e) {
      console.log(e);
    }
    var notiTime = sleepTimes[i];
    jobs[i] = schedule.scheduleJob(sleepTimes[i], function()
  {
    checkToShowNotification(notiTime);
  }); //scheduling notification jobs
  }
  try {
  if (jobs[6] != null)
  {
    jobs[6].cancel();
  }
    if (upTimeJob != null)
    {
    upTimeJob.cancel();
  }
  } catch (e) {
    console.log(e);
  }
github eeg1412 / wikimoeCardByNodeJS / server / utils / check.js View on Github external
const timeNow = Math.floor(new Date().getTime()/3600000);
    const dataTime = guessCardData?guessCardData.time:0;
    if(!guessCardData){
        console.info(
            chalk.yellow('目前不存在猜卡数据,系统将自动生成!')
        );
        guessCard.creatNewGuessCard();
        this.deletOldUserGuessCard();
    }else if(dataTime{
        guessCard.creatNewGuessCard();
        this.deletOldUserGuessCard();
    }); 
}
exports.checkOldPost = ()=>{
github nowke / realtime-dashboard-demo / worker / worker.js View on Github external
const start = async () => {
  console.log("Starting worker");
  const s1 = schedule.scheduleJob("*/3 * * * * *", async () => {
    await makeHttpRequest("CPU");
    console.log("Fetched new results for CPU");
  });
  const s2 = schedule.scheduleJob("*/5 * * * * *", async () => {
    await makeHttpRequest("TRAFFIC");
    console.log("Fetched new results for TRAFFIC");
  });
  const s3 = schedule.scheduleJob("*/4 * * * * *", async () => {
    await makeHttpRequest("DISTRIBUTION");
    console.log("Fetched new results for DISTRIBUTION");
  });
  const s4 = schedule.scheduleJob("*/3 * * * * *", async () => {
    await makeHttpRequest("MESSAGES");
    console.log("Fetched new results for MESSAGES");
  });
  console.log("Scheduled Jobs for CPU, Traffic, distribution, messages");
};
github r3volved / LaZBot / utilities / schedule-handler.js View on Github external
setSchedule( channelID, name, dateTime, cadence ) {
        
        let rule = new schedule.RecurrenceRule();
        
        rule.hour = dateTime.getHours();
        rule.minute = dateTime.getMinutes();
        
        if( !!cadence && cadence === "weekly" ) { rule.dayOfWeek = dateTime.getDay(); } 
        else if( !!cadence && cadence === "daily" ) { rule.dayOfWeek = [new schedule.Range(0, 6)]; } 
        else { rule = dateTime; }

        this.jobs.set(`${channelID}-${name}`, schedule.scheduleJob(rule, function(scheduler, channelID, name) {
          
            scheduler.alert(channelID, name);
            
        }.bind(null, this, channelID, name)));
        
        return this;
    
    }
github nebrius / aquarium-control / server / src / server.js View on Github external
function scheduleSunset(time) {
	schedule.scheduleJob(time, function () {
		scheduleUpdate();
	});
}
github nest-cloud / nestcloud / packages / schedule / scheduler.ts View on Github external
public static scheduleCronJob(
    key: string,
    cron: string,
    cb: JobCallback,
    config?: ICronJobConfig,
    tryLock?: Promise | TryLock,
  ) {
    const configs = Object.assign({}, defaults, config);
    const instance = schedule.scheduleJob(
      {
        start: config.startTime,
        end: config.endTime,
        rule: cron,
      },
      async () => {
        const job = this.jobs.get(key);
        if (configs.waiting && job.status !== READY) {
          return false;
        }
        job.status = RUNNING;

        const executor = new Executor(configs);

        job.status = READY;
        const needStop = await executor.execute(key, cb, tryLock);

node-schedule

A cron-like and not-cron-like job scheduler for Node.

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis