Skip to content

Commit 95ad817

Browse files
committed
Cleanup context and execution creation, cache stuff, add parent and root task run ids
1 parent 5ea6605 commit 95ad817

File tree

25 files changed

+980
-254
lines changed

25 files changed

+980
-254
lines changed

apps/webapp/app/presenters/v3/SpanPresenter.server.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import {
2-
type MachinePresetName,
3-
prettyPrintPacket,
4-
SemanticInternalAttributes,
5-
TaskRunError,
6-
} from "@trigger.dev/core/v3";
1+
import { prettyPrintPacket, SemanticInternalAttributes, TaskRunError } from "@trigger.dev/core/v3";
72
import { getMaxDuration } from "@trigger.dev/core/v3/isomorphic";
83
import { RUNNING_STATUSES } from "~/components/runs/v3/TaskRunStatus";
94
import { logger } from "~/services/logger.server";
105
import { eventRepository, rehydrateAttribute } from "~/v3/eventRepository.server";
11-
import { machinePresetFromName, machinePresetFromRun } from "~/v3/machinePresets.server";
6+
import { machinePresetFromRun } from "~/v3/machinePresets.server";
127
import { getTaskEventStoreTableForRun, type TaskEventStoreTable } from "~/v3/taskEventStore.server";
138
import { isFailedRunStatus, isFinalRunStatus } from "~/v3/taskStatus";
149
import { BasePresenter } from "./basePresenter.server";
@@ -132,11 +127,7 @@ export class SpanPresenter extends BasePresenter {
132127
isTest: true,
133128
maxDurationInSeconds: true,
134129
taskEventStore: true,
135-
tags: {
136-
select: {
137-
name: true,
138-
},
139-
},
130+
runTags: true,
140131
machinePreset: true,
141132
lockedToVersion: {
142133
select: {
@@ -274,12 +265,12 @@ export class SpanPresenter extends BasePresenter {
274265
const context = {
275266
task: {
276267
id: run.taskIdentifier,
277-
filePath: run.lockedBy?.filePath,
268+
filePath: run.lockedBy?.filePath ?? "",
278269
},
279270
run: {
280271
id: run.friendlyId,
281272
createdAt: run.createdAt,
282-
tags: run.tags.map((tag) => tag.name),
273+
tags: run.runTags,
283274
isTest: run.isTest,
284275
idempotencyKey: run.idempotencyKey ?? undefined,
285276
startedAt: run.startedAt ?? run.createdAt,
@@ -292,6 +283,7 @@ export class SpanPresenter extends BasePresenter {
292283
},
293284
queue: {
294285
name: run.queue,
286+
id: run.queue,
295287
},
296288
environment: {
297289
id: run.runtimeEnvironment.id,
@@ -342,7 +334,7 @@ export class SpanPresenter extends BasePresenter {
342334
isCustomQueue: !run.queue.startsWith("task/"),
343335
concurrencyKey: run.concurrencyKey,
344336
},
345-
tags: run.tags.map((tag) => tag.name),
337+
tags: run.runTags,
346338
baseCostInCents: run.baseCostInCents,
347339
costInCents: run.costInCents,
348340
totalCostInCents: run.costInCents + run.baseCostInCents,

apps/webapp/app/routes/resources.runs.$runParam.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
7676
lockedBy: {
7777
select: {
7878
filePath: true,
79+
worker: {
80+
select: {
81+
deployment: {
82+
select: {
83+
friendlyId: true,
84+
shortCode: true,
85+
version: true,
86+
runtime: true,
87+
runtimeVersion: true,
88+
git: true,
89+
},
90+
},
91+
},
92+
},
93+
},
94+
},
95+
parentTaskRun: {
96+
select: {
97+
friendlyId: true,
98+
},
99+
},
100+
rootTaskRun: {
101+
select: {
102+
friendlyId: true,
79103
},
80104
},
81105
},
@@ -163,6 +187,8 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
163187
baseCostInCents: run.baseCostInCents,
164188
maxAttempts: run.maxAttempts ?? undefined,
165189
version: run.lockedToVersion?.version,
190+
parentTaskRunId: run.parentTaskRun?.friendlyId ?? undefined,
191+
rootTaskRunId: run.rootTaskRun?.friendlyId ?? undefined,
166192
},
167193
queue: {
168194
name: run.queue,
@@ -184,6 +210,16 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
184210
name: run.project.name,
185211
},
186212
machine: run.machinePreset ? machinePresetFromRun(run) : undefined,
213+
deployment: run.lockedBy?.worker.deployment
214+
? {
215+
id: run.lockedBy.worker.deployment.friendlyId,
216+
shortCode: run.lockedBy.worker.deployment.shortCode,
217+
version: run.lockedBy.worker.deployment.version,
218+
runtime: run.lockedBy.worker.deployment.runtime,
219+
runtimeVersion: run.lockedBy.worker.deployment.runtimeVersion,
220+
git: run.lockedBy.worker.deployment.git,
221+
}
222+
: undefined,
187223
};
188224

189225
return typedjson({

apps/webapp/app/v3/failedTaskRun.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
TaskRunExecution,
55
TaskRunExecutionRetry,
66
TaskRunFailedExecutionResult,
7+
V3TaskRunExecution,
78
} from "@trigger.dev/core/v3";
89
import type { Prisma, TaskRun } from "@trigger.dev/database";
910
import * as semver from "semver";
@@ -129,7 +130,7 @@ export class FailedTaskRunRetryHelper extends BaseService {
129130
async #getRetriableAttemptExecution(
130131
run: TaskRunWithAttempts,
131132
completion: TaskRunFailedExecutionResult
132-
): Promise<TaskRunExecution | undefined> {
133+
): Promise<V3TaskRunExecution | undefined> {
133134
let attempt = run.attempts[0];
134135

135136
// We need to create an attempt if:

apps/webapp/app/v3/marqs/devQueueConsumer.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Context, ROOT_CONTEXT, Span, SpanKind, context, trace } from "@opentelemetry/api";
22
import {
3-
TaskRunExecution,
3+
V3TaskRunExecution,
44
TaskRunExecutionLazyAttemptPayload,
55
TaskRunExecutionResult,
66
TaskRunFailedExecutionResult,
@@ -138,7 +138,7 @@ export class DevQueueConsumer {
138138
public async taskAttemptCompleted(
139139
workerId: string,
140140
completion: TaskRunExecutionResult,
141-
execution: TaskRunExecution
141+
execution: V3TaskRunExecution
142142
) {
143143
if (completion.ok) {
144144
this._taskSuccesses++;

apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
import {
1212
AckCallbackResult,
1313
MachinePreset,
14-
ProdTaskRunExecution,
15-
ProdTaskRunExecutionPayload,
14+
V3ProdTaskRunExecution,
15+
V3ProdTaskRunExecutionPayload,
1616
TaskRunError,
1717
TaskRunErrorCodes,
1818
TaskRunExecution,
@@ -1679,7 +1679,7 @@ class SharedQueueTasks {
16791679
private async _executionFromAttempt(
16801680
attempt: AttemptForExecution,
16811681
machinePreset?: MachinePreset
1682-
): Promise<ProdTaskRunExecution> {
1682+
): Promise<V3ProdTaskRunExecution> {
16831683
const { backgroundWorkerTask, taskRun, queue } = attempt;
16841684

16851685
if (!machinePreset) {
@@ -1693,7 +1693,7 @@ class SharedQueueTasks {
16931693
dataType: taskRun.metadataType,
16941694
});
16951695

1696-
const execution: ProdTaskRunExecution = {
1696+
const execution: V3ProdTaskRunExecution = {
16971697
task: {
16981698
id: backgroundWorkerTask.slug,
16991699
filePath: backgroundWorkerTask.filePath,
@@ -1784,7 +1784,7 @@ class SharedQueueTasks {
17841784
setToExecuting?: boolean;
17851785
isRetrying?: boolean;
17861786
skipStatusChecks?: boolean;
1787-
}): Promise<ProdTaskRunExecutionPayload | undefined> {
1787+
}): Promise<V3ProdTaskRunExecutionPayload | undefined> {
17881788
const attempt = await prisma.taskRunAttempt.findFirst({
17891789
where: {
17901790
id,
@@ -1874,7 +1874,7 @@ class SharedQueueTasks {
18741874
machinePreset
18751875
);
18761876

1877-
const payload: ProdTaskRunExecutionPayload = {
1877+
const payload: V3ProdTaskRunExecutionPayload = {
18781878
execution,
18791879
traceContext: taskRun.traceContext as Record<string, unknown>,
18801880
environment: variables.reduce((acc: Record<string, string>, curr) => {
@@ -1888,7 +1888,7 @@ class SharedQueueTasks {
18881888

18891889
async getResumePayload(attemptId: string): Promise<
18901890
| {
1891-
execution: ProdTaskRunExecution;
1891+
execution: V3ProdTaskRunExecution;
18921892
completion: TaskRunExecutionResult;
18931893
}
18941894
| undefined
@@ -1927,7 +1927,7 @@ class SharedQueueTasks {
19271927

19281928
async getResumePayloads(attemptIds: string[]): Promise<
19291929
Array<{
1930-
execution: ProdTaskRunExecution;
1930+
execution: V3ProdTaskRunExecution;
19311931
completion: TaskRunExecutionResult;
19321932
}>
19331933
> {
@@ -1985,7 +1985,7 @@ class SharedQueueTasks {
19851985
id: string,
19861986
setToExecuting?: boolean,
19871987
isRetrying?: boolean
1988-
): Promise<ProdTaskRunExecutionPayload | undefined> {
1988+
): Promise<V3ProdTaskRunExecutionPayload | undefined> {
19891989
const run = await prisma.taskRun.findFirst({
19901990
where: {
19911991
id,

apps/webapp/app/v3/services/completeAttempt.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { Attributes } from "@opentelemetry/api";
22
import {
33
MachinePresetName,
44
TaskRunContext,
5-
TaskRunError,
65
TaskRunErrorCodes,
76
TaskRunExecution,
87
TaskRunExecutionResult,
98
TaskRunExecutionRetry,
109
TaskRunFailedExecutionResult,
1110
TaskRunSuccessfulExecutionResult,
11+
V3TaskRunExecution,
1212
flattenAttributes,
1313
isOOMRunError,
1414
sanitizeError,
@@ -60,7 +60,7 @@ export class CompleteAttemptService extends BaseService {
6060
checkpoint,
6161
}: {
6262
completion: TaskRunExecutionResult;
63-
execution: TaskRunExecution;
63+
execution: V3TaskRunExecution;
6464
env?: AuthenticatedEnvironment;
6565
checkpoint?: CheckpointData;
6666
}): Promise<"COMPLETED" | "RETRIED"> {
@@ -196,7 +196,7 @@ export class CompleteAttemptService extends BaseService {
196196
checkpoint,
197197
}: {
198198
completion: TaskRunFailedExecutionResult;
199-
execution: TaskRunExecution;
199+
execution: V3TaskRunExecution;
200200
taskRunAttempt: NonNullable<FoundAttempt>;
201201
env?: AuthenticatedEnvironment;
202202
checkpoint?: CheckpointData;
@@ -559,7 +559,7 @@ export class CompleteAttemptService extends BaseService {
559559
forceRequeue = false,
560560
oomMachine,
561561
}: {
562-
execution: TaskRunExecution;
562+
execution: V3TaskRunExecution;
563563
executionRetry: TaskRunExecutionRetry;
564564
executionRetryInferred: boolean;
565565
taskRunAttempt: NonNullable<FoundAttempt>;
@@ -648,7 +648,7 @@ export class CompleteAttemptService extends BaseService {
648648
executionRetryInferred,
649649
checkpoint,
650650
}: {
651-
execution: TaskRunExecution;
651+
execution: V3TaskRunExecution;
652652
taskRunAttempt: NonNullable<FoundAttempt>;
653653
executionRetry: TaskRunExecutionRetry;
654654
executionRetryInferred: boolean;

apps/webapp/app/v3/services/createTaskRunAttempt.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parsePacket, TaskRunExecution } from "@trigger.dev/core/v3";
1+
import { parsePacket, V3TaskRunExecution } from "@trigger.dev/core/v3";
22
import { TaskRun, TaskRunAttempt } from "@trigger.dev/database";
33
import { MAX_TASK_RUN_ATTEMPTS } from "~/consts";
44
import { $transaction, prisma, PrismaClientOrTransaction } from "~/db.server";
@@ -25,7 +25,7 @@ export class CreateTaskRunAttemptService extends BaseService {
2525
setToExecuting?: boolean;
2626
startAtZero?: boolean;
2727
}): Promise<{
28-
execution: TaskRunExecution;
28+
execution: V3TaskRunExecution;
2929
run: TaskRun;
3030
attempt: TaskRunAttempt;
3131
}> {
@@ -189,7 +189,7 @@ export class CreateTaskRunAttemptService extends BaseService {
189189
dataType: taskRun.metadataType,
190190
});
191191

192-
const execution: TaskRunExecution = {
192+
const execution: V3TaskRunExecution = {
193193
task: {
194194
id: lockedBy.slug,
195195
filePath: lockedBy.filePath,

internal-packages/cache/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Redis
2+
3+
This is a simple package that is used to return a valid Redis client and provides an error callback. It will log and swallow errors if they're not handled.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@internal/cache",
3+
"private": true,
4+
"version": "0.0.1",
5+
"main": "./src/index.ts",
6+
"types": "./src/index.ts",
7+
"type": "module",
8+
"dependencies": {
9+
"@unkey/cache": "^1.5.0",
10+
"@unkey/error": "^0.2.0",
11+
"@trigger.dev/core": "workspace:*",
12+
"@internal/redis": "workspace:*",
13+
"superjson": "^2.2.1"
14+
},
15+
"scripts": {
16+
"typecheck": "tsc --noEmit"
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export {
2+
createCache,
3+
DefaultStatefulContext,
4+
Namespace,
5+
type Cache as UnkeyCache,
6+
} from "@unkey/cache";
7+
export { MemoryStore } from "@unkey/cache/stores";
8+
export { RedisCacheStore } from "./stores/redis.js";

0 commit comments

Comments
 (0)