aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers/abstract-scheduler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/schedulers/abstract-scheduler.ts')
-rw-r--r--server/lib/schedulers/abstract-scheduler.ts35
1 files changed, 0 insertions, 35 deletions
diff --git a/server/lib/schedulers/abstract-scheduler.ts b/server/lib/schedulers/abstract-scheduler.ts
deleted file mode 100644
index f3d51a22e..000000000
--- a/server/lib/schedulers/abstract-scheduler.ts
+++ /dev/null
@@ -1,35 +0,0 @@
1import Bluebird from 'bluebird'
2import { logger } from '../../helpers/logger'
3
4export abstract class AbstractScheduler {
5
6 protected abstract schedulerIntervalMs: number
7
8 private interval: NodeJS.Timer
9 private isRunning = false
10
11 enable () {
12 if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.')
13
14 this.interval = setInterval(() => this.execute(), this.schedulerIntervalMs)
15 }
16
17 disable () {
18 clearInterval(this.interval)
19 }
20
21 async execute () {
22 if (this.isRunning === true) return
23 this.isRunning = true
24
25 try {
26 await this.internalExecute()
27 } catch (err) {
28 logger.error('Cannot execute %s scheduler.', this.constructor.name, { err })
29 } finally {
30 this.isRunning = false
31 }
32 }
33
34 protected abstract internalExecute (): Promise<any> | Bluebird<any>
35}