Skip to content

Commit bded496

Browse files
authored
Merge pull request #112 from samply/fix/dont-retry-expired-task
fix: Dont retry expired task
2 parents c3bdd6d + af69ce7 commit bded496

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/beam.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::time::Duration;
22

33
use beam_lib::{TaskResult, BeamClient, BlockingOptions, MsgId, TaskRequest, RawString};
4+
use http::StatusCode;
45
use once_cell::sync::Lazy;
56
use serde::Serialize;
67
use tracing::{debug, warn};
@@ -85,20 +86,28 @@ pub async fn retrieve_tasks() -> Result<Vec<TaskRequest<String>>, FocusError> {
8586
.map_err(FocusError::UnableToRetrieveTasksHttp)
8687
}
8788

88-
pub async fn answer_task<T: Serialize + 'static>(task_id: MsgId, result: &TaskResult<T>) -> Result<bool, FocusError> {
89+
pub async fn answer_task<T: Serialize + 'static>(task_id: MsgId, result: &TaskResult<T>) -> Result<(), FocusError> {
8990
debug!("Answer task with id: {task_id}");
9091
BEAM_CLIENT.put_result(result, &task_id)
9192
.await
92-
.map_err(FocusError::UnableToAnswerTask)
93+
.map(|_| ())
94+
.or_else(|e| match e {
95+
beam_lib::BeamError::UnexpectedStatus(s) if s == StatusCode::NOT_FOUND => Ok(()),
96+
other => Err(FocusError::UnableToAnswerTask(other))
97+
})
9398
}
9499

95-
pub async fn fail_task<T>(task: &TaskRequest<T>, body: impl Into<String>) -> Result<bool, FocusError> {
100+
pub async fn fail_task<T>(task: &TaskRequest<T>, body: impl Into<String>) -> Result<(), FocusError> {
96101
let body = body.into();
97102
warn!("Reporting failed task with id {}: {}", task.id, body);
98103
let result = beam_result::perm_failed(CONFIG.beam_app_id_long.clone(), vec![task.from.clone()], task.id, body);
99104
BEAM_CLIENT.put_result(&result, &task.id)
100105
.await
101-
.map_err(FocusError::UnableToAnswerTask)
106+
.map(|_| ())
107+
.or_else(|e| match e {
108+
beam_lib::BeamError::UnexpectedStatus(s) if s == StatusCode::NOT_FOUND => Ok(()),
109+
other => Err(FocusError::UnableToAnswerTask(other))
110+
})
102111
}
103112

104113
pub async fn claim_task<T>(task: &TaskRequest<T>) -> Result<bool, FocusError> {

0 commit comments

Comments
 (0)