Parcourir la source

fix(core): Further stability improvement to default scheduler

Michael Bromley il y a 7 mois
Parent
commit
664b919e37

+ 13 - 5
packages/core/src/plugin/default-scheduler-plugin/default-scheduler-strategy.ts

@@ -186,11 +186,19 @@ export class DefaultSchedulerStrategy implements SchedulerStrategy {
         if (!this.connection.rawConnection.isInitialized) {
             return;
         }
-        const taskEntities = await this.connection.rawConnection
-            .getRepository(ScheduledTaskRecord)
-            .createQueryBuilder('task')
-            .where('task.manuallyTriggeredAt IS NOT NULL')
-            .getMany();
+        let taskEntities: ScheduledTaskRecord[] = [];
+        try {
+            taskEntities = await this.connection.rawConnection
+                .getRepository(ScheduledTaskRecord)
+                .createQueryBuilder('task')
+                .where('task.manuallyTriggeredAt IS NOT NULL')
+                .getMany();
+        } catch (e) {
+            // This branch can be reached if the connection is closed and then this method
+            // is called on the interval. Usually encountered in tests.
+            const errorMessage = e instanceof Error ? e.message : 'Unknown error';
+            Logger.error(`Error checking for manually triggered tasks: ${errorMessage}`);
+        }
 
         Logger.debug(`Checking for manually triggered tasks: ${taskEntities.length}`);