aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-12-02 02:27:20 +0300
committereug-vs <eug-vs@keemail.me>2020-12-02 02:30:38 +0300
commit2069909287866003d63e9ea7862b2273ec73e2d5 (patch)
treefad1aa2715a9a25a494ea35cba1eebfc392b7be7
parent4186fb51f66043b221237c7ba91ac5a95a4f32b0 (diff)
downloadmongo-cronjob-2069909287866003d63e9ea7862b2273ec73e2d5.tar.gz
feat: allow to start/stop scheduler polling
-rw-r--r--lib/scheduler.ts18
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() {