forge
Explore
Log in

Don't you dare go Hollow

The runner waits out a forge restart while uploading artifacts, as it already did for the job result

Browse files at this commit

e910f7ef7eff7fd34da03beb69028dcce5ab820fAhmet Kaan GümüşParent: fec5ec5
All checks have passed
Show checks
  • 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
Show full message
🐛 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
crates/forge-runner/src/runner.rsmodified+29 -16
@@ -24,7 +24,7 @@ use crate::update::{self, Installed, UpdateState};
24 use crate::workspace;24 use crate::workspace;
25 25
26 const LOG_CHANNEL: usize = 64;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 const MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024;28 const MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024;
29 const LOG_FLUSH: Duration = Duration::from_secs(5);29 const LOG_FLUSH: Duration = Duration::from_secs(5);
30 30
@@ -457,8 +457,10 @@ impl Runner {
457 let found = artifacts::collect(dir, &job.artifacts, MAX_ARTIFACT_BYTES)457 let found = artifacts::collect(dir, &job.artifacts, MAX_ARTIFACT_BYTES)
458 .map_err(|e| format!("artifacts: {e}"))?;458 .map_err(|e| format!("artifacts: {e}"))?;
459 for artifact in &found {459 for artifact in &found {
460+ patiently(&job.job_id, "artifact upload", || {
460 self.client461 self.client
461 .upload_artifact(&job.job_id, &job.job_token, &artifact.name, &artifact.path)462 .upload_artifact(&job.job_id, &job.job_token, &artifact.name, &artifact.path)
463+ })
462 .await464 .await
463 .map_err(|e| format!("artifact {}: {e}", artifact.name))?;465 .map_err(|e| format!("artifact {}: {e}", artifact.name))?;
464 }466 }
@@ -474,31 +476,42 @@ impl Runner {
474 oom_killed: oom_kills.map(|_| true),476 oom_killed: oom_kills.map(|_| true),
475 oom_kills,477 oom_kills,
476 };478 };
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;
485+ }
486+ tracing::error!(
487+ job_id = %job.job_id,
488+ "could not report the job result; the forge will reap it after heartbeats stop"
489+ );
490+ }
491+}
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+{
477 let started = Instant::now();498 let started = Instant::now();
478 let mut attempt = 0u32;499 let mut attempt = 0u32;
479 loop {500 loop {
480 attempt += 1;501 attempt += 1;
481- match self.client.finish(&job.job_id, &job.job_token, &req).await {502+ let Err(e) = op().await else {
482- Ok(()) => return,503+ return Ok(());
483- Err(e) => {504+ };
484- tracing::warn!(job_id = %job.job_id, attempt, error = %e, "finish failed");505+ tracing::warn!(job_id, attempt, error = %e, "{what} failed");
485 let away = match &e {506 let away = match &e {
486 ClientError::Http(_) => true,507 ClientError::Http(_) => true,
487 ClientError::Status { status, .. } => status.is_server_error(),508 ClientError::Status { status, .. } => status.is_server_error(),
488 _ => false,509 _ => false,
489 };510 };
490- if !away || started.elapsed() >= FINISH_PATIENCE {511+ if !away || started.elapsed() >= FORGE_PATIENCE {
491- break;512+ return Err(e);
492- }
493- let wait = Duration::from_secs((2 * u64::from(attempt)).min(15));
494- tokio::time::sleep(wait).await;
495- }
496 }513 }
497- }514+ tokio::time::sleep(Duration::from_secs((2 * u64::from(attempt)).min(15))).await;
498- tracing::error!(
499- job_id = %job.job_id,
500- "could not report the job result; the forge will reap it after heartbeats stop"
501- );
502 }515 }
503 }516 }
504 517