diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/scheduler.ts | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/scheduler.ts b/lib/scheduler.ts index 28d09cc..1d52c35 100644 --- a/lib/scheduler.ts +++ b/lib/scheduler.ts @@ -4,16 +4,28 @@ import { EventModel } from './event.model'; const CronJob = cron.CronJob; +const defaultPollingInterval = '*/10 * * * * *'; + + class Scheduler { + job: cron.CronJob; jobs: cron.CronJob[]; Model: EventModel<any>; - constructor(model: EventModel<any>) { + constructor(model: EventModel<any>, pollingInterval = defaultPollingInterval) { this.Model = model; this.jobs = []; - const job = new CronJob('*/10 * * * * *', () => this.updateJobs()); - job.start(); + this.job = new CronJob(pollingInterval, () => this.updateJobs()); + this.startPolling(); + } + + startPolling() { + this.job.start(); + } + + stopPolling() { + this.job.stop(); } startAllJobs() { |