Skip to content

Commit 8df5234

Browse files
committed
CompletedService final pair
1 parent 065c5c9 commit 8df5234

File tree

1 file changed

+14
-47
lines changed

1 file changed

+14
-47
lines changed

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

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -288,35 +288,6 @@ export class CompleteAttemptService extends BaseService {
288288

289289
return "RETRIED";
290290
} else {
291-
/*
292-
"SYSTEM_FAILURE"
293-
Steps:
294-
1. marqs ack
295-
2. Completes the run span OTEL event
296-
3. Crash all incomplete OTEL events
297-
4. Updates the run to system failure
298-
299-
OR
300-
301-
"COMPLETED_WITH_ERRORS"
302-
Steps:
303-
1. marqs ack
304-
2. Completes the run span OTEL event
305-
3. Updates the run to completed with errors
306-
4. Enqueues resuming task run dependencies
307-
308-
Inputs:
309-
- taskRun: id, spanId
310-
- taskRunAttempt: id
311-
- error message
312-
- Prisma client/transaction
313-
*/
314-
315-
// No more retries, we need to fail the task run
316-
logger.debug("Completed attempt, ACKing message", taskRunAttempt);
317-
318-
await marqs?.acknowledgeMessage(taskRunAttempt.taskRunId);
319-
320291
// Now we need to "complete" the task run event/span
321292
await eventRepository.completeEvent(taskRunAttempt.taskRun.spanId, {
322293
endTime: new Date(),
@@ -338,6 +309,14 @@ export class CompleteAttemptService extends BaseService {
338309
sanitizedError.type === "INTERNAL_ERROR" &&
339310
sanitizedError.code === "GRACEFUL_EXIT_TIMEOUT"
340311
) {
312+
const finalizeService = new FinalizeTaskRunService();
313+
await finalizeService.call({
314+
tx: this._prisma,
315+
id: taskRunAttempt.taskRunId,
316+
status: "SYSTEM_FAILURE",
317+
completedAt: new Date(),
318+
});
319+
341320
// We need to fail all incomplete spans
342321
const inProgressEvents = await eventRepository.queryIncompleteEvents({
343322
attemptId: execution.attempt.id,
@@ -361,25 +340,13 @@ export class CompleteAttemptService extends BaseService {
361340
});
362341
})
363342
);
364-
365-
await this._prisma.taskRun.update({
366-
where: {
367-
id: taskRunAttempt.taskRunId,
368-
},
369-
data: {
370-
status: "SYSTEM_FAILURE",
371-
completedAt: new Date(),
372-
},
373-
});
374343
} else {
375-
await this._prisma.taskRun.update({
376-
where: {
377-
id: taskRunAttempt.taskRunId,
378-
},
379-
data: {
380-
status: "COMPLETED_WITH_ERRORS",
381-
completedAt: new Date(),
382-
},
344+
const finalizeService = new FinalizeTaskRunService();
345+
await finalizeService.call({
346+
tx: this._prisma,
347+
id: taskRunAttempt.taskRunId,
348+
status: "COMPLETED_WITH_ERRORS",
349+
completedAt: new Date(),
383350
});
384351
}
385352

0 commit comments

Comments
 (0)