Skip to content

Instantly share code, notes, and snippets.

@sebastiaanluca
Last active December 6, 2015 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastiaanluca/b8edac61b693d3db2f23 to your computer and use it in GitHub Desktop.
Save sebastiaanluca/b8edac61b693d3db2f23 to your computer and use it in GitHub Desktop.
Triggers an alarm every hour at 10 minutes, a sub job every minute after that for about 10 minutes, and a snooze at 30 minutes.
var Moment = require('moment');
var Schedule = require('node-schedule');
var alarmJob;
var fixedSnoozeJob;
var subCounter;
//
// Schedule the jobs
console.log('Setting up jobs');
alarmJob = Schedule.scheduleJob({minute: 10}, function () {
console.log('[ALARM1] Alarm triggered! It is now %s', Moment().format('MMMM Do YYYY, h:mm:ss a'));
subCounter = 0;
Schedule.scheduleJob('*/1 * * * *', function () {
console.log('[ALARM 1 - SUB 1] Gradually increasing volume');
if (subCounter >= 10) {
this.cancel();
return;
}
++subCounter;
});
});
fixedSnoozeJob = Schedule.scheduleJob({minute: 30}, function () {
console.log('[ALARM2] Force-snoozing alarm. Stopping playback. It is now %s', Moment().format('MMMM Do YYYY, h:mm:ss a'));
});
//
console.log('BOOTED');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment