-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtestTask.server.ts
More file actions
93 lines (88 loc) · 3.29 KB
/
testTask.server.ts
File metadata and controls
93 lines (88 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { stringifyIO } from "@trigger.dev/core/v3";
import { type AuthenticatedEnvironment } from "~/services/apiAuth.server";
import { type TestTaskData } from "../testTask";
import { BaseService } from "./baseService.server";
import { TriggerTaskService } from "./triggerTask.server";
export class TestTaskService extends BaseService {
public async call(environment: AuthenticatedEnvironment, data: TestTaskData) {
const triggerTaskService = new TriggerTaskService();
const { triggerSource } = data;
switch (triggerSource) {
case "STANDARD": {
const result = await triggerTaskService.call(
data.taskIdentifier,
environment,
{
payload: data.payload,
options: {
test: true,
metadata: data.metadata,
delay: data.delaySeconds
? new Date(Date.now() + data.delaySeconds * 1000)
: undefined,
ttl: data.ttlSeconds,
idempotencyKey: data.idempotencyKey,
idempotencyKeyTTL: data.idempotencyKeyTTLSeconds
? `${data.idempotencyKeyTTLSeconds}s`
: undefined,
queue: data.queue ? { name: data.queue } : undefined,
concurrencyKey: data.concurrencyKey,
maxAttempts: data.maxAttempts,
maxDuration: data.maxDurationSeconds,
tags: data.tags,
machine: data.machine,
region: data.region,
lockToVersion: data.version === "latest" ? undefined : data.version,
priority: data.prioritySeconds,
},
},
{ triggerSource: "dashboard", triggerAction: "test" }
);
return result?.run;
}
case "SCHEDULED": {
const payload = {
scheduleId: "sched_1234",
type: "IMPERATIVE",
timestamp: data.timestamp,
lastTimestamp: data.lastTimestamp,
timezone: data.timezone,
externalId: data.externalId,
upcoming: [],
};
const payloadPacket = await stringifyIO(payload);
const result = await triggerTaskService.call(
data.taskIdentifier,
environment,
{
payload: payloadPacket.data,
options: {
payloadType: payloadPacket.dataType,
test: true,
ttl: data.ttlSeconds,
idempotencyKey: data.idempotencyKey,
idempotencyKeyTTL: data.idempotencyKeyTTLSeconds
? `${data.idempotencyKeyTTLSeconds}s`
: undefined,
queue: data.queue ? { name: data.queue } : undefined,
concurrencyKey: data.concurrencyKey,
maxAttempts: data.maxAttempts,
maxDuration: data.maxDurationSeconds,
tags: data.tags,
machine: data.machine,
region: data.region,
lockToVersion: data.version === "latest" ? undefined : data.version,
priority: data.prioritySeconds,
},
},
{ customIcon: "scheduled", triggerSource: "dashboard", triggerAction: "test" }
);
return result?.run;
}
default: {
triggerSource satisfies never;
throw new Error("Invalid trigger source");
}
}
}
}