Skip to content

Commit fd5ceee

Browse files
committed
fix(api): prevent duplicate email notifications for failed tasks
1 parent 1bb1f5d commit fd5ceee

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

apps/api/src/trigger/browser-automation/run-browser-automation.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,20 @@ export const runBrowserAutomation = task({
304304
data: { status: 'failed' },
305305
});
306306

307-
// Send email notifications
308-
await sendTaskStatusChangeEmails({
309-
organizationId,
310-
taskId,
311-
taskTitle,
312-
oldStatus,
313-
newStatus: 'failed',
314-
});
307+
// Only send email notifications if status actually changed
308+
if (oldStatus !== 'failed') {
309+
await sendTaskStatusChangeEmails({
310+
organizationId,
311+
taskId,
312+
taskTitle,
313+
oldStatus,
314+
newStatus: 'failed',
315+
});
316+
} else {
317+
logger.info(
318+
`Skipping notification: task ${taskId} was already in failed status`,
319+
);
320+
}
315321
}
316322
}
317323

apps/api/src/trigger/integration-platform/run-task-integration-checks.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,20 @@ export const runTaskIntegrationChecks = task({
407407
`Task ${taskId} marked as failed due to ${totalFindings} findings${hasFailedChecks ? ' and failed checks' : ''}`,
408408
);
409409

410-
// Send email notifications
411-
await sendTaskStatusChangeEmails({
412-
organizationId,
413-
taskId,
414-
taskTitle,
415-
oldStatus,
416-
newStatus: 'failed',
417-
});
410+
// Only send email notifications if status actually changed
411+
if (oldStatus !== 'failed') {
412+
await sendTaskStatusChangeEmails({
413+
organizationId,
414+
taskId,
415+
taskTitle,
416+
oldStatus,
417+
newStatus: 'failed',
418+
});
419+
} else {
420+
logger.info(
421+
`Skipping notification: task ${taskId} was already in failed status`,
422+
);
423+
}
418424
} else if (totalPassing > 0) {
419425
// Only update to done if not already done
420426
const currentTask = await db.task.findUnique({

0 commit comments

Comments
 (0)