Cron task for salak.
- Three mode: single、worker and all.
singlemeans the task will be trigger on the only one thread in the only one machine.workermeans the task will be trigger on the only one thread in every machine.allmeans the task will be trigger on every thread
- Task can trigger service.
npm install --save salak-schedule
const schedule = require('salak-schedule')
schedule(options, app)load schedule from dir schedule under every module.
const { Service } = require('salak')
class Task extends Service {
static timer () {
return {
enable: true, // default true
interval: 1000,
type: 'all', // single、all、worker, default 'all'
cron: '* * * * * *', // use `cron-parser`
cronOptions: {}
}
}
async run () { // for the task logic
}
}- Store: for
singleorworker,default redisStore - prefix: for
singleorworker,default 'salakTimer' - options: options for Store. default app.redis
- key:
${module}.${taskfilename}
class AStore {
lock (key, ttl) {}
unlock (lock) {}
}
module.exports = AStoreMIT