MCPcopy
hub / github.com/triggerdotdev/trigger.dev / action

Function action

apps/webapp/app/routes/api.v1.schedules.ts:16–76  ·  view source on GitHub ↗
({ request }: ActionFunctionArgs)

Source from the content-addressed store, hash-verified

14});
15
16export async function action({ request }: ActionFunctionArgs) {
17 // Ensure this is a POST request
18 if (request.method.toUpperCase() !== "POST") {
19 return { status: 405, body: "Method Not Allowed" };
20 }
21
22 // Authenticate the request
23 const authenticationResult = await authenticateApiRequest(request);
24
25 if (!authenticationResult) {
26 return json({ error: "Invalid or Missing API Key" }, { status: 401 });
27 }
28
29 const rawBody = await request.json();
30
31 const body = CreateScheduleOptions.safeParse(rawBody);
32
33 if (!body.success) {
34 return json({ error: "Invalid request body", issues: body.error.issues }, { status: 400 });
35 }
36
37 const service = new UpsertTaskScheduleService();
38
39 try {
40 const options: UpsertSchedule = {
41 taskIdentifier: body.data.task,
42 cron: body.data.cron,
43 environments: [authenticationResult.environment.id],
44 externalId: body.data.externalId,
45 deduplicationKey: body.data.deduplicationKey,
46 };
47
48 const schedule = await service.call(authenticationResult.environment.projectId, options);
49
50 const responseObject: ScheduleObject = {
51 id: schedule.id,
52 task: schedule.task,
53 active: schedule.active,
54 generator: {
55 type: "CRON",
56 expression: schedule.cron,
57 description: schedule.cronDescription,
58 },
59 externalId: schedule.externalId ?? undefined,
60 deduplicationKey: schedule.deduplicationKey,
61 environments: schedule.environments,
62 nextRun: schedule.nextRun,
63 };
64
65 return json(responseObject, { status: 200 });
66 } catch (error) {
67 if (error instanceof ServiceValidationError) {
68 return json({ error: error.message }, { status: 422 });
69 }
70
71 return json(
72 { error: error instanceof Error ? error.message : "Internal Server Error" },
73 { status: 500 }

Callers

nothing calls this directly

Calls 4

callMethod · 0.95
authenticateApiRequestFunction · 0.90
jsonFunction · 0.85
jsonMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…