Skip to content

Commit baac879

Browse files
committed
feat(core): make run queue a public API field
Add queue to CommonRunFields so RetrieveRunResponse/ListRunResponseItem carry it, document it in the OpenAPI schema, and omit it (rather than sending an empty string) on a buffered run that doesn't have one yet.
1 parent be495dc commit baac879

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@trigger.dev/core": patch
3+
"@trigger.dev/sdk": patch
4+
---
5+
6+
Run objects returned by `runs.retrieve()` and `runs.list()` now include the run's `queue` name.

‎apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ type CommonRelatedRunWithVersion = CommonRelatedRun & {
8686
// ReturnType<typeof findRun>) so findRun can return a synthesised buffered
8787
// run without the type becoming self-referential. Exported so the
8888
// buffer-synthesis helper below can match this shape under unit test.
89-
export type FoundRun = CommonRelatedRunWithVersion & {
89+
export type FoundRun = Omit<CommonRelatedRunWithVersion, "queue"> & {
90+
// Optional here only because a buffered (mollified) run may not carry it yet;
91+
// a Postgres-resident run always has one (see commonRunSelect).
92+
queue?: string;
9093
traceId: string;
9194
payload: string;
9295
payloadType: string;
@@ -523,7 +526,7 @@ export class ApiRetrieveRunPresenter {
523526
}
524527
}
525528

526-
async function resolveSchedule(run: CommonRelatedRun) {
529+
async function resolveSchedule(run: Pick<CommonRelatedRun, "scheduleId">) {
527530
if (!run.scheduleId) {
528531
return undefined;
529532
}
@@ -551,7 +554,9 @@ async function resolveSchedule(run: CommonRelatedRun) {
551554
}
552555

553556
async function createCommonRunStructure(
554-
run: CommonRelatedRunWithVersion,
557+
// `queue` is widened to optional: a Postgres-resident run always has one, but a
558+
// buffered (mollified) run synthesised into `FoundRun` may not yet.
559+
run: Omit<CommonRelatedRunWithVersion, "queue"> & { queue?: string },
555560
apiVersion: API_VERSIONS
556561
) {
557562
const metadata = await parsePacketAsJson({
@@ -591,7 +596,9 @@ async function createCommonRunStructure(
591596
};
592597
}
593598

594-
function resolveTriggerFunction(run: CommonRelatedRun): TriggerFunction {
599+
function resolveTriggerFunction(
600+
run: Pick<CommonRelatedRun, "batch" | "resumeParentOnCompletion">
601+
): TriggerFunction {
595602
if (run.batch) {
596603
return run.resumeParentOnCompletion ? "batchTriggerAndWait" : "batchTrigger";
597604
} else {
@@ -698,7 +705,7 @@ export function synthesiseFoundRunFromBuffer(buffered: SyntheticRun): FoundRun {
698705
startedAt: null,
699706
// Buffered runs live in Redis until the drainer replays them into Postgres — never queued there yet.
700707
queuedAt: null,
701-
queue: buffered.queue ?? "",
708+
queue: buffered.queue,
702709
updatedAt: buffered.cancelledAt ?? buffered.createdAt,
703710
// PG-resident SYSTEM_FAILURE rows always have `completedAt` set by
704711
// the engine; the buffer-synth path must match so SDK consumers

‎docs/v3-openapi.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5549,6 +5549,10 @@ components:
55495549
type: string
55505550
example: 20240523.1
55515551
description: The version of the worker that executed the run
5552+
queue:
5553+
type: string
5554+
description: The name of the queue the run was placed in
5555+
example: task/my-task
55525556
idempotencyKey:
55535557
type: string
55545558
description: The idempotency key used to prevent creating duplicate runs, if provided

‎packages/core/src/v3/schemas/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ const CommonRunFields = {
13591359
metadata: z.record(z.any()).optional(),
13601360
taskKind: z.string().optional(),
13611361
region: z.string().optional(),
1362+
queue: z.string().optional(),
13621363
};
13631364

13641365
const RetrieveRunCommandFields = {

0 commit comments

Comments
 (0)