({
runId,
leaveRunning = true, // This mirrors kubernetes behaviour more accurately
projectRef,
deploymentVersion,
}: CheckpointAndPushOptions)
| 350 | } |
| 351 | |
| 352 | async #checkpointAndPush({ |
| 353 | runId, |
| 354 | leaveRunning = true, // This mirrors kubernetes behaviour more accurately |
| 355 | projectRef, |
| 356 | deploymentVersion, |
| 357 | }: CheckpointAndPushOptions): Promise<CheckpointAndPushResult> { |
| 358 | await this.initialize(); |
| 359 | |
| 360 | const options = { |
| 361 | runId, |
| 362 | leaveRunning, |
| 363 | projectRef, |
| 364 | deploymentVersion, |
| 365 | }; |
| 366 | |
| 367 | if (!this.#dockerMode && !this.#canCheckpoint) { |
| 368 | this.#logger.error("No checkpoint support. Simulation requires docker."); |
| 369 | return { success: false, reason: "NO_SUPPORT" }; |
| 370 | } |
| 371 | |
| 372 | if (this.#abortControllers.has(runId)) { |
| 373 | logger.error("Checkpoint procedure already in progress", { options }); |
| 374 | return { success: false, reason: "IN_PROGRESS" }; |
| 375 | } |
| 376 | |
| 377 | // This is a new checkpoint, clear any last failure for this run |
| 378 | this.#clearFailedCheckpoint(runId); |
| 379 | |
| 380 | if (DISABLE_CHECKPOINT_SUPPORT) { |
| 381 | this.#logger.error("Checkpoint support disabled", { options }); |
| 382 | return { success: false, reason: "DISABLED" }; |
| 383 | } |
| 384 | |
| 385 | const controller = new AbortController(); |
| 386 | this.#abortControllers.set(runId, controller); |
| 387 | |
| 388 | const $$ = $({ signal: controller.signal }); |
| 389 | |
| 390 | const shortCode = nanoid(8); |
| 391 | const imageRef = this.#getImageRef(projectRef, deploymentVersion, shortCode); |
| 392 | const exportLocation = this.#getExportLocation(projectRef, deploymentVersion, shortCode); |
| 393 | |
| 394 | const cleanup = async () => { |
| 395 | if (this.#dockerMode) { |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | try { |
| 400 | await $`rm ${exportLocation}`; |
| 401 | this.#logger.log("Deleted checkpoint archive", { exportLocation }); |
| 402 | |
| 403 | await $`buildah rmi ${imageRef}`; |
| 404 | this.#logger.log("Deleted checkpoint image", { imageRef }); |
| 405 | } catch (error) { |
| 406 | this.#logger.error("Failure during checkpoint cleanup", { exportLocation, error }); |
| 407 | } |
| 408 | }; |
| 409 |
no test coverage detected