for better error, especially from sentry cron monitor (#12574)
After release 55, we found out that CRON job monitor was red for CronTriggerCronJob While only 1 workspace was not in the appropriate state, meaning the whole command was probably failing for only 1 workspace failing. We suggest here to catch errors per worksspace and simply push to sentry the error of the errored workspace relative to workflow trigger.
This commit is contained in:
@ -5,6 +5,7 @@ import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
|
|||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
import { SentryCronMonitor } from 'src/engine/core-modules/cron/sentry-cron-monitor.decorator';
|
import { SentryCronMonitor } from 'src/engine/core-modules/cron/sentry-cron-monitor.decorator';
|
||||||
|
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||||
@ -33,6 +34,7 @@ export class CronTriggerCronJob {
|
|||||||
@InjectMessageQueue(MessageQueue.workflowQueue)
|
@InjectMessageQueue(MessageQueue.workflowQueue)
|
||||||
private readonly messageQueueService: MessageQueueService,
|
private readonly messageQueueService: MessageQueueService,
|
||||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||||
|
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Process(CronTriggerCronJob.name)
|
@Process(CronTriggerCronJob.name)
|
||||||
@ -47,38 +49,46 @@ export class CronTriggerCronJob {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
for (const activeWorkspace of activeWorkspaces) {
|
for (const activeWorkspace of activeWorkspaces) {
|
||||||
const workflowAutomatedTriggerRepository =
|
try {
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WorkflowAutomatedTriggerWorkspaceEntity>(
|
const workflowAutomatedTriggerRepository =
|
||||||
activeWorkspace.id,
|
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WorkflowAutomatedTriggerWorkspaceEntity>(
|
||||||
'workflowAutomatedTrigger',
|
activeWorkspace.id,
|
||||||
);
|
'workflowAutomatedTrigger',
|
||||||
|
);
|
||||||
|
|
||||||
const workflowAutomatedCronTriggers =
|
const workflowAutomatedCronTriggers =
|
||||||
await workflowAutomatedTriggerRepository.find({
|
await workflowAutomatedTriggerRepository.find({
|
||||||
where: { type: AutomatedTriggerType.CRON },
|
where: { type: AutomatedTriggerType.CRON },
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const workflowAutomatedCronTrigger of workflowAutomatedCronTriggers) {
|
for (const workflowAutomatedCronTrigger of workflowAutomatedCronTriggers) {
|
||||||
const settings =
|
const settings =
|
||||||
workflowAutomatedCronTrigger.settings as CronTriggerSettings;
|
workflowAutomatedCronTrigger.settings as CronTriggerSettings;
|
||||||
|
|
||||||
if (!isDefined(settings.pattern)) {
|
if (!isDefined(settings.pattern)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldRunNow(settings.pattern, now)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.messageQueueService.add<WorkflowTriggerJobData>(
|
||||||
|
WorkflowTriggerJob.name,
|
||||||
|
{
|
||||||
|
workspaceId: activeWorkspace.id,
|
||||||
|
workflowId: workflowAutomatedCronTrigger.workflowId,
|
||||||
|
payload: {},
|
||||||
|
},
|
||||||
|
{ retryLimit: 3 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
if (!shouldRunNow(settings.pattern, now)) {
|
this.exceptionHandlerService.captureExceptions([error], {
|
||||||
continue;
|
workspace: {
|
||||||
}
|
id: activeWorkspace.id,
|
||||||
|
|
||||||
await this.messageQueueService.add<WorkflowTriggerJobData>(
|
|
||||||
WorkflowTriggerJob.name,
|
|
||||||
{
|
|
||||||
workspaceId: activeWorkspace.id,
|
|
||||||
workflowId: workflowAutomatedCronTrigger.workflowId,
|
|
||||||
payload: {},
|
|
||||||
},
|
},
|
||||||
{ retryLimit: 3 },
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user