From 2069909287866003d63e9ea7862b2273ec73e2d5 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 2 Dec 2020 02:27:20 +0300 Subject: feat: allow to start/stop scheduler polling --- lib/scheduler.ts | 18 +++++++++++++++--- 1 file 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; - constructor(model: EventModel) { + constructor(model: EventModel, 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() { -- cgit v1.2.3