Cron task for salak.
- Three mode: single、worker and all.
single
means the task will be trigger on the only one thread in the only one machine.worker
means the task will be trigger on the only one thread in every machine.all
means 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
single
orworker
,default redisStore - prefix: for
single
orworker
,default 'salakTimer' - options: options for Store. default app.redis
- key:
${module}.${taskfilename}
class AStore {
lock (key, ttl) {}
unlock (lock) {}
}
module.exports = AStore
MIT