1 import { logger } from '../../helpers/logger'
2 import * as Bluebird from 'bluebird'
4 export abstract class AbstractScheduler {
6 protected abstract schedulerIntervalMs: number
8 private interval: NodeJS.Timer
9 private isRunning = false
12 if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.')
14 this.interval = setInterval(() => this.execute(), this.schedulerIntervalMs)
18 clearInterval(this.interval)
22 if (this.isRunning === true) return
26 await this.internalExecute()
28 logger.error('Cannot execute %s scheduler.', this.constructor.name, { err })
30 this.isRunning = false
34 protected abstract internalExecute (): Promise<any> | Bluebird<any>