1 import { logger } from '../../helpers/logger'
3 export abstract class AbstractScheduler {
5 protected abstract schedulerIntervalMs: number
7 private interval: NodeJS.Timer
8 private isRunning = false
11 if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.')
13 this.interval = setInterval(() => this.execute(), this.schedulerIntervalMs)
17 clearInterval(this.interval)
21 if (this.isRunning === true) return
25 await this.internalExecute()
27 logger.error('Cannot execute %s scheduler.', this.constructor.name, { err })
29 this.isRunning = false
33 protected abstract internalExecute (): Promise<any>