9ecf07731a
* add checkpoint restore events * fix retries.enabledInDev * fix tsconfig paths * fix provider build and dev * update kubernetes provider and fix builds again * upgrade prod base to node 20 * update infra publish workflow * rethrow k8s errors after logging * shorten index container names * fix error type assertion * rename type assertion * remove resource limits for now * add missing run id on create * add push to deploy command for self-hosting * checkpointing fixes * update coordinator image * ensure valid registry login * delete checkpoint archive after successful push * log options on error * structured logs for socket connections * fix structured log merge * exit process after checkpointing * update restore pull secret name * append shortcode to restore names * log handler payload * disable post start lifecycle hook * pass in coordinator host via volume * replace dapi with taskinfo * add missing restore label * don't restart restored containers * remove init container from create * atomic post-completion checkpoints * switch to run id for container names * improve wait accuracy * measure basic checkpoint perf * always log disconnect reason * use system clock to end wait spans * checkpoint readiness and cancel signals * restore from checkpoint events and fix statuses * remove attempt id env var * restore dependencies from events * reconnect wip * lifecycle hooks are back * fix hooks and improve reconnect * make docker send postStart hook * only checkpoint for retry if large delay * fix a few more resume issues * lifecycle hook fixes * skip connection handler when waiting for post start hook --------- Co-authored-by: Eric Allam <eric@trigger.dev>
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import type { CheckpointRestoreEvent, CheckpointRestoreEventType } from "@trigger.dev/database";
|
|
import { logger } from "~/services/logger.server";
|
|
import { BaseService } from "./baseService.server";
|
|
|
|
interface CheckpointRestoreEventCallParams {
|
|
checkpointId: string;
|
|
type: CheckpointRestoreEventType;
|
|
dependencyFriendlyRunId?: string;
|
|
batchDependencyFriendlyId?: string;
|
|
}
|
|
|
|
type CheckpointRestoreEventParams = Omit<CheckpointRestoreEventCallParams, "type">;
|
|
|
|
export class CreateCheckpointRestoreEventService extends BaseService {
|
|
async checkpoint(params: CheckpointRestoreEventParams) {
|
|
return this.#call({ ...params, type: "CHECKPOINT" });
|
|
}
|
|
|
|
async restore(params: CheckpointRestoreEventParams) {
|
|
return this.#call({ ...params, type: "RESTORE" });
|
|
}
|
|
|
|
async #call(
|
|
params: CheckpointRestoreEventCallParams
|
|
): Promise<CheckpointRestoreEvent | undefined> {
|
|
if (params.dependencyFriendlyRunId && params.batchDependencyFriendlyId) {
|
|
logger.error("Only one dependency can be set", { params });
|
|
return;
|
|
}
|
|
|
|
const checkpoint = await this._prisma.checkpoint.findUnique({
|
|
where: {
|
|
id: params.checkpointId,
|
|
},
|
|
});
|
|
|
|
if (!checkpoint) {
|
|
logger.error("Checkpoint not found", { id: params.checkpointId });
|
|
return;
|
|
}
|
|
|
|
logger.debug(`Creating checkpoint/restore event`, { params });
|
|
|
|
let taskRunDependencyId: string | undefined;
|
|
|
|
if (params.dependencyFriendlyRunId) {
|
|
const run = await this._prisma.taskRun.findUnique({
|
|
where: {
|
|
friendlyId: params.dependencyFriendlyRunId,
|
|
},
|
|
select: {
|
|
id: true,
|
|
dependency: {
|
|
select: {
|
|
id: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
taskRunDependencyId = run?.dependency?.id;
|
|
|
|
if (!taskRunDependencyId) {
|
|
logger.error("Dependency or run not found", { runId: params.dependencyFriendlyRunId });
|
|
return;
|
|
}
|
|
}
|
|
|
|
const checkpointEvent = await this._prisma.checkpointRestoreEvent.create({
|
|
data: {
|
|
checkpointId: checkpoint.id,
|
|
runtimeEnvironmentId: checkpoint.runtimeEnvironmentId,
|
|
projectId: checkpoint.projectId,
|
|
attemptId: checkpoint.attemptId,
|
|
runId: checkpoint.runId,
|
|
type: params.type,
|
|
reason: checkpoint.reason,
|
|
metadata: checkpoint.metadata,
|
|
...(taskRunDependencyId
|
|
? {
|
|
taskRunDependency: {
|
|
connect: {
|
|
id: taskRunDependencyId,
|
|
},
|
|
},
|
|
}
|
|
: undefined),
|
|
...(params.batchDependencyFriendlyId
|
|
? {
|
|
batchTaskRunDependency: {
|
|
connect: {
|
|
friendlyId: params.batchDependencyFriendlyId,
|
|
},
|
|
},
|
|
}
|
|
: undefined),
|
|
},
|
|
});
|
|
|
|
return checkpointEvent;
|
|
}
|
|
}
|