mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Disable Cron hooks when only the CLI is running (#8490)
Depends on #8478 Fixes #8457
This commit is contained in:
committed by
GitHub
parent
cb3c8492d2
commit
1389586593
@@ -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 });
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user