Cron-like schedule driver for Cycle.js
Install with NPM
npm install --save cycle-schedule-driver
Import the driver:
const makeScheduleDriver = require('cycle-schedule-driver')
Register the driver:
const drivers = {
...
schedule: makeScheduleDriver()
}
The general convention for scheduling jobs is as so:
sources.schedule.select(cron)
Or optionally with a name:
sources.schedule.select(cron, name)
Since this driver is based on node-schedule, it supports all the requests formats the library supports.
You can pass a cron string:
sources.schedule.schedule('59 * * * * *', 'optional_name')
Where the convention is as so:
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
The most human friendly option is to just pass in a JSON object:
sources.schedule.schedule({ second: 10 })
Finally, you can also just schedule it to run at a specific date:
sources.schedule.schedule(dateObject)
Named jobs can be cancelled by sending the name into the sink:
{
...
schedule: xs.of('dummy') // Kills the dummy job
}
A very basic sample that covers all use cases is available in the sample/
folder.
Application started at 2/22/2017, 2:52:54 PM
Final second is at 2/22/2017, 2:51:59 PM
We have encountered second number 10 1 times
One minute has passed since application started
We have encountered second number 10 2 times
We have encountered second number 10 3 times
We have encountered second number 10 4 times
We have encountered second number 10 5 times