diff --git a/src/beam.rs b/src/beam.rs index 7979ef9..d67ef9f 100644 --- a/src/beam.rs +++ b/src/beam.rs @@ -1,6 +1,7 @@ use std::time::Duration; use beam_lib::{TaskResult, BeamClient, BlockingOptions, MsgId, TaskRequest, RawString}; +use http::StatusCode; use once_cell::sync::Lazy; use serde::Serialize; use tracing::{debug, warn}; @@ -85,20 +86,28 @@ pub async fn retrieve_tasks() -> Result>, FocusError> { .map_err(FocusError::UnableToRetrieveTasksHttp) } -pub async fn answer_task(result: &TaskResult) -> Result { +pub async fn answer_task(result: &TaskResult) -> Result<(), FocusError> { debug!("Answer task with id: {}", result.task); BEAM_CLIENT.put_result(result, &result.task) - .await - .map_err(FocusError::UnableToAnswerTask) + .await + .map(|_| ()) + .or_else(|e| match e { + beam_lib::BeamError::UnexpectedStatus(s) if s == StatusCode::NOT_FOUND => Ok(()), + other => Err(FocusError::UnableToAnswerTask(other)) + }) } -pub async fn fail_task(task: &TaskRequest, body: impl Into) -> Result { +pub async fn fail_task(task: &TaskRequest, body: impl Into) -> Result<(), FocusError> { let body = body.into(); warn!("Reporting failed task with id {}: {}", task.id, body); let result = beam_result::perm_failed(CONFIG.beam_app_id_long.clone(), vec![task.from.clone()], task.id, body); BEAM_CLIENT.put_result(&result, &task.id) .await - .map_err(FocusError::UnableToAnswerTask) + .map(|_| ()) + .or_else(|e| match e { + beam_lib::BeamError::UnexpectedStatus(s) if s == StatusCode::NOT_FOUND => Ok(()), + other => Err(FocusError::UnableToAnswerTask(other)) + }) } pub async fn claim_task(task: &TaskRequest) -> Result { diff --git a/src/task_processing.rs b/src/task_processing.rs index 1f5da91..dddaa1f 100644 --- a/src/task_processing.rs +++ b/src/task_processing.rs @@ -98,6 +98,15 @@ async fn process_task( execute: true, }); + if metadata.project == "focus-healthcheck" { + return Ok(beam::beam_result::succeeded( + CONFIG.beam_app_id_long.clone(), + vec![task.from.clone()], + task.id, + "healthy".into() + )); + } + if metadata.project == "exporter" { let body = &task.body; return Ok(run_exporter_query(task, body, metadata.execute).await)?;