aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/schedulers/abstract-scheduler.ts
blob: 6ec5e336069a137768689884fad9f7bb37ab5e1c (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                         

                                                


                                


                                                                                    







                                
export abstract class AbstractScheduler {

  protected abstract schedulerIntervalMs: number

  private interval: NodeJS.Timer

  enable () {
    if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.')

    this.interval = setInterval(() => this.execute(), this.schedulerIntervalMs)
  }

  disable () {
    clearInterval(this.interval)
  }

  protected abstract execute ()
}