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+38 -25
@@ -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,10 +457,12 @@ 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- self.client460+ patiently(&job.job_id, "artifact upload", || {
461- .upload_artifact(&job.job_id, &job.job_token, &artifact.name, &artifact.path)461+ self.client
462- .await462+ .upload_artifact(&job.job_id, &job.job_token, &artifact.name, &artifact.path)
463- .map_err(|e| format!("artifact {}: {e}", artifact.name))?;463+ })
464+ .await
465+ .map_err(|e| format!("artifact {}: {e}", artifact.name))?;
464 }466 }
465 tracing::info!(job_id = %job.job_id, count = found.len(), "artifacts uploaded");467 tracing::info!(job_id = %job.job_id, count = found.len(), "artifacts uploaded");
466 Ok(())468 Ok(())
@@ -474,26 +476,12 @@ impl Runner {
474 oom_killed: oom_kills.map(|_| true),476 oom_killed: oom_kills.map(|_| true),
475 oom_kills,477 oom_kills,
476 };478 };
477- let started = Instant::now();479+ let reported = patiently(&job.job_id, "finish", || {
478- let mut attempt = 0u32;480+ self.client.finish(&job.job_id, &job.job_token, &req)
479- loop {481+ })
480- attempt += 1;482+ .await;
481- match self.client.finish(&job.job_id, &job.job_token, &req).await {483+ if reported.is_ok() {
482- Ok(()) => return,484+ 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- }
497 }485 }
498 tracing::error!(486 tracing::error!(
499 job_id = %job.job_id,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 fn not_claiming(last: &mut Option<String>, reason: String) {518 fn not_claiming(last: &mut Option<String>, reason: String) {
506 if last.as_deref() != Some(reason.as_str()) {519 if last.as_deref() != Some(reason.as_str()) {
507 tracing::info!("not claiming: {reason}");520 tracing::info!("not claiming: {reason}");