1.0.6 • Published 5 years ago
salak-schedule v1.0.6
salak-schedule
Cron task for salak.
Feature
- 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.
Install
npm install --save salak-schedule
Usage
const SalakSchedule = require('salak-schedule')
const timerHandler = new SalakSchedule({
app: this.app,
prefix,
store: new SalakSchedule.stores['memory']()
})
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
}
}
API
schedule options
- Store: for
single
orworker
,default redisStore - prefix: for
single
orworker
,default 'salakTimer' - options: options for Store. default app.redis
Timer
getSchedules()
runSchedule(key)
- key:
${module}.${taskfilename}
closeSchedules()
Write a store
class AStore {
lock (key, ttl) {}
unlock (lock) {}
}
module.exports = AStore
License
MIT
2.0.0-beta.3
5 years ago
2.0.0-beta.2
5 years ago
2.0.0-beta.1
5 years ago
1.0.6
6 years ago
2.0.0-beta
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago