diff options
Diffstat (limited to 'server/lib/schedulers/abstract-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/abstract-scheduler.ts | 35 |
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 @@ | |||
1 | import Bluebird from 'bluebird' | ||
2 | import { logger } from '../../helpers/logger' | ||
3 | |||
4 | export 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 | } | ||