From 7f7889ee8ae67ff1a6dade71b21d1bc8f2b51ae6 Mon Sep 17 00:00:00 2001 From: Tom Marcuzzi Date: Mon, 6 Jan 2025 17:58:55 +0100 Subject: [PATCH] Fix optional filter for action cron --- src/core/actions/src/action-job.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/actions/src/action-job.ts b/src/core/actions/src/action-job.ts index 4b41e55c..d3e8a832 100644 --- a/src/core/actions/src/action-job.ts +++ b/src/core/actions/src/action-job.ts @@ -3,6 +3,7 @@ import { Action } from './action-manager'; import { ActionApp } from './app/action-app'; import { ActionError } from './error/error'; import { errorCodes } from './error/errorcodes'; +import { FilterQuery } from 'mongoose'; export class ActionCron { maxTimeToConsumeAnAction = 10 * 60 * 1000; @@ -64,9 +65,8 @@ export class ActionCron { } getAction() { - return this.app.ActionModel.findOne({ + let query = { state: { $lte: ActionState.CLOSED }, - filter: this.filter, $or: [ { 'cronActivity.pending': false, @@ -84,7 +84,12 @@ export class ActionCron { }, }, ], - }) + } as FilterQuery; + + if (this.filter) + query.filter = this.filter; + + return this.app.ActionModel.findOne(query) .sort('cronActivity.lastActivity') .then((action) => action); }