Skip to content

Commit 2cfea9c

Browse files
committed
Cleaned up the update metadata endpoint and added an API doc page for it
1 parent 99f23e6 commit 2cfea9c

File tree

4 files changed

+143
-20
lines changed

4 files changed

+143
-20
lines changed

apps/webapp/app/routes/api.v1.runs.$runId.metadata.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { type ActionFunctionArgs, json } from "@remix-run/server-runtime";
2-
import { AddTagsRequestBody, parsePacket, UpdateMetadataRequestBody } from "@trigger.dev/core/v3";
2+
import { parsePacket, UpdateMetadataRequestBody } from "@trigger.dev/core/v3";
33
import { z } from "zod";
44
import { prisma } from "~/db.server";
5-
import { createTag, getTagsForRunId, MAX_TAGS_PER_RUN } from "~/models/taskRunTag.server";
65
import { authenticateApiRequest } from "~/services/apiAuth.server";
76
import { handleMetadataPacket } from "~/utils/packets";
87
import { ServiceValidationError } from "~/v3/services/baseService.server";
9-
import { FINAL_RUN_STATUSES } from "~/v3/taskStatus";
8+
import { isFinalRunStatus } from "~/v3/taskStatus";
109

1110
const ParamsSchema = z.object({
1211
runId: z.string(),
1312
});
1413

1514
export async function action({ request, params }: ActionFunctionArgs) {
16-
// Ensure this is a POST request
15+
// Ensure this is a PUT request
1716
if (request.method.toUpperCase() !== "PUT") {
18-
return { status: 405, body: "Method Not Allowed" };
17+
return json({ error: "Method not allowed" }, { status: 405, headers: { Allow: "PUT" } });
1918
}
2019

2120
// Authenticate the request
@@ -64,7 +63,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
6463
return json({ error: "Task Run not found" }, { status: 404 });
6564
}
6665

67-
if (FINAL_RUN_STATUSES.includes(taskRun.status)) {
66+
if (isFinalRunStatus(taskRun.status)) {
6867
return json({ error: "Cannot update metadata for a completed run" }, { status: 400 });
6968
}
7069

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: "Update metadata"
3+
openapi: "v3-openapi PUT /api/v1/runs/{runId}/metadata"
4+
---

docs/mint.json

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"$schema": "https://mintlify.com/schema.json",
33
"name": "Trigger.dev",
4-
"openapi": ["/openapi.yml", "/v3-openapi.yaml"],
4+
"openapi": [
5+
"/openapi.yml",
6+
"/v3-openapi.yaml"
7+
],
58
"api": {
69
"playground": {
710
"mode": "simple"
@@ -103,26 +106,41 @@
103106
"navigation": [
104107
{
105108
"group": "Getting Started",
106-
"pages": ["introduction", "quick-start", "how-it-works", "upgrading-beta", "limits"]
109+
"pages": [
110+
"introduction",
111+
"quick-start",
112+
"how-it-works",
113+
"upgrading-beta",
114+
"limits"
115+
]
107116
},
108117
{
109118
"group": "Fundamentals",
110119
"pages": [
111120
{
112121
"group": "Tasks",
113-
"pages": ["tasks/overview", "tasks/scheduled"]
122+
"pages": [
123+
"tasks/overview",
124+
"tasks/scheduled"
125+
]
114126
},
115127
"triggering",
116128
"apikeys",
117129
{
118130
"group": "Configuration",
119-
"pages": ["config/config-file", "config/extensions/overview"]
131+
"pages": [
132+
"config/config-file",
133+
"config/extensions/overview"
134+
]
120135
}
121136
]
122137
},
123138
{
124139
"group": "Development",
125-
"pages": ["cli-dev", "run-tests"]
140+
"pages": [
141+
"cli-dev",
142+
"run-tests"
143+
]
126144
},
127145
{
128146
"group": "Deployment",
@@ -132,7 +150,9 @@
132150
"github-actions",
133151
{
134152
"group": "Deployment integrations",
135-
"pages": ["vercel-integration"]
153+
"pages": [
154+
"vercel-integration"
155+
]
136156
}
137157
]
138158
},
@@ -144,7 +164,13 @@
144164
"errors-retrying",
145165
{
146166
"group": "Wait",
147-
"pages": ["wait", "wait-for", "wait-until", "wait-for-event", "wait-for-request"]
167+
"pages": [
168+
"wait",
169+
"wait-for",
170+
"wait-until",
171+
"wait-for-event",
172+
"wait-for-request"
173+
]
148174
},
149175
"queue-concurrency",
150176
"versioning",
@@ -162,7 +188,10 @@
162188
"management/overview",
163189
{
164190
"group": "Tasks API",
165-
"pages": ["management/tasks/trigger", "management/tasks/batch-trigger"]
191+
"pages": [
192+
"management/tasks/trigger",
193+
"management/tasks/batch-trigger"
194+
]
166195
},
167196
{
168197
"group": "Runs API",
@@ -171,7 +200,8 @@
171200
"management/runs/retrieve",
172201
"management/runs/replay",
173202
"management/runs/cancel",
174-
"management/runs/reschedule"
203+
"management/runs/reschedule",
204+
"management/runs/update-metadata"
175205
]
176206
},
177207
{
@@ -200,7 +230,9 @@
200230
},
201231
{
202232
"group": "Projects API",
203-
"pages": ["management/projects/runs"]
233+
"pages": [
234+
"management/projects/runs"
235+
]
204236
}
205237
]
206238
},
@@ -246,7 +278,11 @@
246278
},
247279
{
248280
"group": "Help",
249-
"pages": ["community", "help-slack", "help-email"]
281+
"pages": [
282+
"community",
283+
"help-slack",
284+
"help-email"
285+
]
250286
},
251287
{
252288
"group": "Frameworks",
@@ -287,16 +323,20 @@
287323
},
288324
{
289325
"group": "Dashboard",
290-
"pages": ["guides/dashboard/creating-a-project"]
326+
"pages": [
327+
"guides/dashboard/creating-a-project"
328+
]
291329
},
292330
{
293331
"group": "Migrations",
294-
"pages": ["guides/use-cases/upgrading-from-v2"]
332+
"pages": [
333+
"guides/use-cases/upgrading-from-v2"
334+
]
295335
}
296336
],
297337
"footerSocials": {
298338
"twitter": "https://twitter.com/triggerdotdev",
299339
"github": "https://github.com/triggerdotdev",
300340
"linkedin": "https://www.linkedin.com/company/triggerdotdev"
301341
}
302-
}
342+
}

docs/v3-openapi.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,86 @@ paths:
360360
361361
const handle = await runs.replay("run_1234");
362362
363+
"/api/v1/runs/{runId}/metadata":
364+
parameters:
365+
- $ref: "#/components/parameters/runId"
366+
put:
367+
operationId: update_run_metadata_v1
368+
summary: Update run metadata
369+
description: Update the metadata of a run.
370+
requestBody:
371+
required: true
372+
content:
373+
application/json:
374+
schema:
375+
type: object
376+
properties:
377+
metadata:
378+
type: object
379+
description: The new metadata to set on the run.
380+
example: { key: "value" }
381+
responses:
382+
"200":
383+
description: Successful request
384+
content:
385+
application/json:
386+
schema:
387+
type: object
388+
properties:
389+
metadata:
390+
type: object
391+
description: The updated metadata of the run.
392+
"400":
393+
description: Invalid request
394+
content:
395+
application/json:
396+
schema:
397+
type: object
398+
properties:
399+
error:
400+
type: string
401+
enum:
402+
- Invalid or missing run ID
403+
- Invalid metadata
404+
"401":
405+
description: Unauthorized request
406+
content:
407+
application/json:
408+
schema:
409+
type: object
410+
properties:
411+
error:
412+
type: string
413+
enum:
414+
- Invalid or Missing API key
415+
"404":
416+
description: Resource not found
417+
content:
418+
application/json:
419+
schema:
420+
type: object
421+
properties:
422+
error:
423+
type: string
424+
enum:
425+
- Task Run not found
426+
tags:
427+
- runs
428+
security:
429+
- secretKey: []
430+
x-codeSamples:
431+
- lang: typescript
432+
label: Update metadata
433+
source: |-
434+
import { metadata, task } from "@trigger.dev/sdk/v3";
435+
436+
export const myTask = task({
437+
id: "my-task",
438+
run: async () => {
439+
await metadata.update({ key: "value" });
440+
}
441+
});
442+
363443
"/api/v2/runs/{runId}/cancel":
364444
parameters:
365445
- $ref: "#/components/parameters/runId"

0 commit comments

Comments
 (0)