The runner waits out a forge restart while uploading artifacts, as it already did for the job result
Browse files at this commite910f7ef7eff7fd34da03beb69028dcce5ab820fParent: fec5ec5All checks have passed
Show checks
ci/buildSucceededDetails
- fix
- the runner waits out a forge restart while uploading artifacts, as it already did for the job result
- a 503 at the end no longer fails a finished run
1 changed file +38 -25
crates/forge-runner/src/runner.rsmodified+38 -25
| @@ -24,7 +24,7 @@ use crate::update::{self, Installed, UpdateState}; | ||
| 24 | 24 | use crate::workspace; |
| 25 | 25 | |
| 26 | 26 | const LOG_CHANNEL: usize = 64; |
| 27 | -const FINISH_PATIENCE: Duration = Duration::from_secs(10 * 60); | |
| 27 | +const FORGE_PATIENCE: Duration = Duration::from_secs(10 * 60); | |
| 28 | 28 | const MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024; |
| 29 | 29 | const LOG_FLUSH: Duration = Duration::from_secs(5); |
| 30 | 30 | |
| @@ -457,10 +457,12 @@ impl Runner { | ||
| 457 | 457 | let found = artifacts::collect(dir, &job.artifacts, MAX_ARTIFACT_BYTES) |
| 458 | 458 | .map_err(|e| format!("artifacts: {e}"))?; |
| 459 | 459 | for artifact in &found { |
| 460 | - self.client | |
| 461 | - .upload_artifact(&job.job_id, &job.job_token, &artifact.name, &artifact.path) | |
| 462 | - .await | |
| 463 | - .map_err(|e| format!("artifact {}: {e}", artifact.name))?; | |
| 460 | + patiently(&job.job_id, "artifact upload", || { | |
| 461 | + self.client | |
| 462 | + .upload_artifact(&job.job_id, &job.job_token, &artifact.name, &artifact.path) | |
| 463 | + }) | |
| 464 | + .await | |
| 465 | + .map_err(|e| format!("artifact {}: {e}", artifact.name))?; | |
| 464 | 466 | } |
| 465 | 467 | tracing::info!(job_id = %job.job_id, count = found.len(), "artifacts uploaded"); |
| 466 | 468 | Ok(()) |
| @@ -474,26 +476,12 @@ impl Runner { | ||
| 474 | 476 | oom_killed: oom_kills.map(|_| true), |
| 475 | 477 | oom_kills, |
| 476 | 478 | }; |
| 477 | - let started = Instant::now(); | |
| 478 | - let mut attempt = 0u32; | |
| 479 | - loop { | |
| 480 | - attempt += 1; | |
| 481 | - match self.client.finish(&job.job_id, &job.job_token, &req).await { | |
| 482 | - Ok(()) => return, | |
| 483 | - Err(e) => { | |
| 484 | - tracing::warn!(job_id = %job.job_id, attempt, error = %e, "finish failed"); | |
| 485 | - let away = match &e { | |
| 486 | - ClientError::Http(_) => true, | |
| 487 | - ClientError::Status { status, .. } => status.is_server_error(), | |
| 488 | - _ => false, | |
| 489 | - }; | |
| 490 | - if !away || started.elapsed() >= FINISH_PATIENCE { | |
| 491 | - break; | |
| 492 | - } | |
| 493 | - let wait = Duration::from_secs((2 * u64::from(attempt)).min(15)); | |
| 494 | - tokio::time::sleep(wait).await; | |
| 495 | - } | |
| 496 | - } | |
| 479 | + let reported = patiently(&job.job_id, "finish", || { | |
| 480 | + self.client.finish(&job.job_id, &job.job_token, &req) | |
| 481 | + }) | |
| 482 | + .await; | |
| 483 | + if reported.is_ok() { | |
| 484 | + return; | |
| 497 | 485 | } |
| 498 | 486 | tracing::error!( |
| 499 | 487 | job_id = %job.job_id, |
| @@ -502,6 +490,31 @@ impl Runner { | ||
| 502 | 490 | } |
| 503 | 491 | } |
| 504 | 492 | |
| 493 | +async fn patiently<F, Fut>(job_id: &str, what: &str, mut op: F) -> Result<(), ClientError> | |
| 494 | +where | |
| 495 | + F: FnMut() -> Fut, | |
| 496 | + Fut: std::future::Future<Output = Result<(), ClientError>>, | |
| 497 | +{ | |
| 498 | + let started = Instant::now(); | |
| 499 | + let mut attempt = 0u32; | |
| 500 | + loop { | |
| 501 | + attempt += 1; | |
| 502 | + let Err(e) = op().await else { | |
| 503 | + return Ok(()); | |
| 504 | + }; | |
| 505 | + tracing::warn!(job_id, attempt, error = %e, "{what} failed"); | |
| 506 | + let away = match &e { | |
| 507 | + ClientError::Http(_) => true, | |
| 508 | + ClientError::Status { status, .. } => status.is_server_error(), | |
| 509 | + _ => false, | |
| 510 | + }; | |
| 511 | + if !away || started.elapsed() >= FORGE_PATIENCE { | |
| 512 | + return Err(e); | |
| 513 | + } | |
| 514 | + tokio::time::sleep(Duration::from_secs((2 * u64::from(attempt)).min(15))).await; | |
| 515 | + } | |
| 516 | +} | |
| 517 | + | |
| 505 | 518 | fn not_claiming(last: &mut Option<String>, reason: String) { |
| 506 | 519 | if last.as_deref() != Some(reason.as_str()) { |
| 507 | 520 | tracing::info!("not claiming: {reason}"); |