X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fschedulers%2Fabstract-scheduler.ts;h=0e6088911752df4a91f8db5e0f531e3af3dd0e15;hb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;hp=b9d0a4d177b715a8fac48a6df7108afab49294db;hpb=4f1f6f038389ce9cdf0c77dfccdc63efc6948101;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/schedulers/abstract-scheduler.ts b/server/lib/schedulers/abstract-scheduler.ts index b9d0a4d17..0e6088911 100644 --- a/server/lib/schedulers/abstract-scheduler.ts +++ b/server/lib/schedulers/abstract-scheduler.ts @@ -1,8 +1,12 @@ +import { logger } from '../../helpers/logger' +import * as Bluebird from 'bluebird' + export abstract class AbstractScheduler { protected abstract schedulerIntervalMs: number private interval: NodeJS.Timer + private isRunning = false enable () { if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.') @@ -14,5 +18,18 @@ export abstract class AbstractScheduler { clearInterval(this.interval) } - abstract execute () + async execute () { + if (this.isRunning === true) return + this.isRunning = true + + try { + await this.internalExecute() + } catch (err) { + logger.error('Cannot execute %s scheduler.', this.constructor.name, { err }) + } finally { + this.isRunning = false + } + } + + protected abstract internalExecute (): Promise | Bluebird }