diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-20 14:31:11 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-20 14:31:11 +0100 |
commit | 2f5c6b2fc6e60502c2a8df4dc9029c1d87ebe30b (patch) | |
tree | 9b83f018403c30421c1b3ca4439c4dddc5077881 /server/lib/schedulers/abstract-scheduler.ts | |
parent | 4707f410ae44b55e17e1758693dd21cff03b7ef1 (diff) | |
download | PeerTube-2f5c6b2fc6e60502c2a8df4dc9029c1d87ebe30b.tar.gz PeerTube-2f5c6b2fc6e60502c2a8df4dc9029c1d87ebe30b.tar.zst PeerTube-2f5c6b2fc6e60502c2a8df4dc9029c1d87ebe30b.zip |
Optimize actor follow scores modifications
Diffstat (limited to 'server/lib/schedulers/abstract-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/abstract-scheduler.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/server/lib/schedulers/abstract-scheduler.ts b/server/lib/schedulers/abstract-scheduler.ts index b9d0a4d17..86ea7aa38 100644 --- a/server/lib/schedulers/abstract-scheduler.ts +++ b/server/lib/schedulers/abstract-scheduler.ts | |||
@@ -1,8 +1,11 @@ | |||
1 | import { logger } from '../../helpers/logger' | ||
2 | |||
1 | export abstract class AbstractScheduler { | 3 | export abstract class AbstractScheduler { |
2 | 4 | ||
3 | protected abstract schedulerIntervalMs: number | 5 | protected abstract schedulerIntervalMs: number |
4 | 6 | ||
5 | private interval: NodeJS.Timer | 7 | private interval: NodeJS.Timer |
8 | private isRunning = false | ||
6 | 9 | ||
7 | enable () { | 10 | enable () { |
8 | if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.') | 11 | if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.') |
@@ -14,5 +17,18 @@ export abstract class AbstractScheduler { | |||
14 | clearInterval(this.interval) | 17 | clearInterval(this.interval) |
15 | } | 18 | } |
16 | 19 | ||
17 | abstract execute () | 20 | async execute () { |
21 | if (this.isRunning === true) return | ||
22 | this.isRunning = true | ||
23 | |||
24 | try { | ||
25 | await this.internalExecute() | ||
26 | } catch (err) { | ||
27 | logger.error('Cannot execute %s scheduler.', this.constructor.name, { err }) | ||
28 | } finally { | ||
29 | this.isRunning = false | ||
30 | } | ||
31 | } | ||
32 | |||
33 | protected abstract internalExecute (): Promise<any> | ||
18 | } | 34 | } |