Skip to content

Commit

Permalink
prevent creating checkpoints for outdated task waits
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktrn committed Oct 17, 2024
1 parent 623f158 commit 11066b4
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions apps/webapp/app/v3/services/createCheckpoint.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ export class CreateCheckpointService extends BaseService {
friendlyId: params.attemptFriendlyId,
},
include: {
taskRun: true,
taskRun: {
include: {
childRuns: {
orderBy: {
createdAt: "asc",
},
take: 1,
},
},
},
backgroundWorker: {
select: {
id: true,
Expand Down Expand Up @@ -93,6 +102,45 @@ export class CreateCheckpointService extends BaseService {
};
}

const { reason } = params;

switch (reason.type) {
case "WAIT_FOR_TASK": {
const lastChildRun = attempt.taskRun.childRuns[0];

if (!lastChildRun) {
logger.warn("CreateCheckpointService: No child runs, creating checkpoint regardless", {
attemptId: attempt.id,
runId: attempt.taskRunId,
params,
});

break;
}

if (lastChildRun.friendlyId !== reason.friendlyId) {
logger.error("CreateCheckpointService: Checkpoint not for most recent child run", {
attemptId: attempt.id,
runId: attempt.taskRunId,
params,
});

return {
success: false,
keepRunAlive: true,
};
}

break;
}
case "WAIT_FOR_BATCH": {
break;
}
default: {
break;
}
}

//sleep to test slow checkpoints
// await new Promise((resolve) => setTimeout(resolve, 60_000));

Expand Down Expand Up @@ -128,8 +176,6 @@ export class CreateCheckpointService extends BaseService {
},
});

const { reason } = params;

let checkpointEvent: CheckpointRestoreEvent | undefined;

switch (reason.type) {
Expand Down

0 comments on commit 11066b4

Please sign in to comment.