Skip to content

Commit afe86ff

Browse files
committed
refactor(run-engine): share the queued snapshot status and description
The trigger path writes this snapshot nested in the run create and emits the timeline event itself, while every re-enqueue writes it through enqueueRun. Keep the status and the default description in one place so the persisted row and the emitted event cannot drift apart.
1 parent a9d0749 commit afe86ff

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

.server-changes/collapse-trigger-queued-snapshot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ area: webapp
33
type: improvement
44
---
55

6-
Triggering a task now reaches the queue marginally faster.
6+
Triggering a task now does one fewer database write, so runs reach the queue slightly faster.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
export const MAX_TASK_RUN_ATTEMPTS = 250;
2+
3+
/**
4+
* The status and description a run's default entry into the queue is written with. Shared because
5+
* the trigger path writes this snapshot nested in the run-create transaction and then emits its own
6+
* `executionSnapshotCreated`, while every re-enqueue writes it through `enqueueRun`. Three places
7+
* have to agree, or the persisted row and the run timeline's `[engine]` entry drift apart.
8+
* Re-enqueues that describe why they requeued pass their own description instead.
9+
*/
10+
export const QUEUED_SNAPSHOT_STATUS = "QUEUED" as const;
11+
export const QUEUED_SNAPSHOT_DESCRIPTION = "Run was QUEUED";

internal-packages/run-engine/src/engine/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { RunQueue } from "../run-queue/index.js";
5454
import { RunQueueFullKeyProducer } from "../run-queue/keyProducer.js";
5555
import type { AuthenticatedEnvironment, MinimalAuthenticatedEnvironment } from "../shared/index.js";
5656
import { BillingCache } from "./billingCache.js";
57+
import { QUEUED_SNAPSHOT_DESCRIPTION, QUEUED_SNAPSHOT_STATUS } from "./consts.js";
5758
import {
5859
ExecutionSnapshotNotFoundError,
5960
NotImplementedError,
@@ -1036,8 +1037,8 @@ export class RunEngine {
10361037
snapshot: {
10371038
id: initialSnapshotId,
10381039
engine: "V2",
1039-
executionStatus: delayUntil ? "DELAYED" : "QUEUED",
1040-
description: delayUntil ? "Run is delayed" : "Run was QUEUED",
1040+
executionStatus: delayUntil ? "DELAYED" : QUEUED_SNAPSHOT_STATUS,
1041+
description: delayUntil ? "Run is delayed" : QUEUED_SNAPSHOT_DESCRIPTION,
10411042
runStatus: status,
10421043
environmentId: environment.id,
10431044
environmentType: environment.type,
@@ -1171,8 +1172,8 @@ export class RunEngine {
11711172
},
11721173
snapshot: {
11731174
id: initialSnapshotId,
1174-
executionStatus: "QUEUED",
1175-
description: "Run was QUEUED",
1175+
executionStatus: QUEUED_SNAPSHOT_STATUS,
1176+
description: QUEUED_SNAPSHOT_DESCRIPTION,
11761177
runStatus: taskRun.status,
11771178
attemptNumber: taskRun.attemptNumber ?? null,
11781179
checkpointId: null,

internal-packages/run-engine/src/engine/systems/enqueueSystem.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
import type { RunStore } from "@internal/run-store";
88
import { parseNaturalLanguageDuration } from "@trigger.dev/core/v3/isomorphic";
99
import type { MinimalAuthenticatedEnvironment } from "../../shared/index.js";
10+
import { QUEUED_SNAPSHOT_DESCRIPTION, QUEUED_SNAPSHOT_STATUS } from "../consts.js";
1011
import type { ExecutionSnapshotSystem } from "./executionSnapshotSystem.js";
1112
import type { SystemResources } from "./systems.js";
1213

@@ -95,8 +96,8 @@ export class EnqueueSystem {
9596
{
9697
run: run,
9798
snapshot: {
98-
executionStatus: snapshot?.status ?? "QUEUED",
99-
description: snapshot?.description ?? "Run was QUEUED",
99+
executionStatus: snapshot?.status ?? QUEUED_SNAPSHOT_STATUS,
100+
description: snapshot?.description ?? QUEUED_SNAPSHOT_DESCRIPTION,
100101
metadata: snapshot?.metadata ?? undefined,
101102
},
102103
previousSnapshotId,

0 commit comments

Comments
 (0)