Disable Cron hooks when only the CLI is running (#8490)

Depends on #8478
Fixes #8457
This commit is contained in:
Nicola Krumschmidt
2021-10-02 00:23:49 +02:00
committed by GitHub
parent cb3c8492d2
commit 1389586593
2 changed files with 12 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ export async function createCli(): Promise<Command> {
const extensionManager = getExtensionManager();
await extensionManager.initialize();
await extensionManager.initialize({ schedule: false });
await emitAsyncSafe('cli.init.before', { program });

View File

@@ -64,11 +64,15 @@ class ExtensionManager {
private endpointRouter: Router;
private isScheduleHookEnabled = true;
constructor() {
this.endpointRouter = Router();
}
public async initialize(): Promise<void> {
public async initialize({ schedule } = { schedule: true }): Promise<void> {
this.isScheduleHookEnabled = schedule;
if (this.isInitialized) return;
try {
@@ -229,10 +233,12 @@ class ExtensionManager {
logger.warn(`Couldn't register cron hook. Provided cron is invalid: ${cron}`);
} else {
const task = schedule(cron, async () => {
try {
await handler();
} catch (error: any) {
logger.error(error);
if (this.isScheduleHookEnabled) {
try {
await handler();
} catch (error: any) {
logger.error(error);
}
}
});