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); }