chore(core): Calculate workflow timeout based on startedAt date of execution (#17137)

This commit is contained in:
Andreas Fitzek
2025-07-10 10:39:56 +02:00
committed by GitHub
parent 8fff83032c
commit 591aa2d20c
5 changed files with 190 additions and 4 deletions

View File

@@ -307,10 +307,21 @@ export class WorkflowRunner {
this.activeExecutions.attachWorkflowExecution(executionId, workflowExecution);
if (workflowTimeout > 0) {
const timeout = Math.min(workflowTimeout, config.getEnv('executions.maxTimeout')) * 1000; // as seconds
executionTimeout = setTimeout(() => {
void this.activeExecutions.stopExecution(executionId);
}, timeout);
let timeout = Math.min(workflowTimeout, config.getEnv('executions.maxTimeout')) * 1000; // as milliseconds
if (data.startedAt && data.startedAt instanceof Date) {
// If startedAt is set, we calculate the timeout based on the startedAt time
// This is useful for executions that were waiting in a waiting state
// and we want to ensure the timeout is relative to when the execution started.
const now = Date.now();
timeout = Math.max(timeout - (now - data.startedAt.getTime()), 0);
}
if (timeout === 0) {
this.activeExecutions.stopExecution(executionId);
} else {
executionTimeout = setTimeout(() => {
void this.activeExecutions.stopExecution(executionId);
}, timeout);
}
}
workflowExecution