Skip to content

Commit 0324dc1

Browse files
committed
add missing service
1 parent e54aa85 commit 0324dc1

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { BaseService } from "./baseService.server";
2+
import { logger } from "~/services/logger.server";
3+
import { isFatalRunStatus } from "../taskStatus";
4+
import { TaskRunErrorCodes, TaskRunInternalError } from "@trigger.dev/core/v3";
5+
import { FinalizeTaskRunService } from "./finalizeTaskRun.server";
6+
7+
export type UpdateFatalRunErrorServiceOptions = {
8+
reason?: string;
9+
exitCode?: number;
10+
logs?: string;
11+
crashAttempts?: boolean;
12+
crashedAt?: Date;
13+
overrideCompletion?: boolean;
14+
errorCode?: TaskRunInternalError["code"];
15+
};
16+
17+
export class UpdateFatalRunErrorService extends BaseService {
18+
public async call(runId: string, options?: UpdateFatalRunErrorServiceOptions) {
19+
const opts = {
20+
reason: "Worker crashed",
21+
crashAttempts: true,
22+
crashedAt: new Date(),
23+
...options,
24+
};
25+
26+
logger.debug("UpdateFatalRunErrorService.call", { runId, opts });
27+
28+
const taskRun = await this._prisma.taskRun.findFirst({
29+
where: {
30+
id: runId,
31+
},
32+
});
33+
34+
if (!taskRun) {
35+
logger.error("[UpdateFatalRunErrorService] Task run not found", { runId });
36+
return;
37+
}
38+
39+
if (!isFatalRunStatus(taskRun.status)) {
40+
logger.warn("[UpdateFatalRunErrorService] Task run is not in a fatal state", {
41+
runId,
42+
status: taskRun.status,
43+
});
44+
45+
return;
46+
}
47+
48+
logger.debug("[UpdateFatalRunErrorService] Updating crash error", { runId, options });
49+
50+
const finalizeService = new FinalizeTaskRunService();
51+
await finalizeService.call({
52+
id: taskRun.id,
53+
status: "CRASHED",
54+
completedAt: new Date(),
55+
error: {
56+
type: "INTERNAL_ERROR",
57+
code: opts.errorCode ?? TaskRunErrorCodes.TASK_RUN_CRASHED,
58+
message: opts.reason,
59+
stackTrace: opts.logs,
60+
},
61+
});
62+
}
63+
}

0 commit comments

Comments
 (0)