|
1 | 1 | use std::time::Duration;
|
2 | 2 |
|
3 | 3 | use beam_lib::{TaskResult, BeamClient, BlockingOptions, MsgId, TaskRequest, RawString};
|
| 4 | +use http::StatusCode; |
4 | 5 | use once_cell::sync::Lazy;
|
5 | 6 | use serde::Serialize;
|
6 | 7 | use tracing::{debug, warn};
|
@@ -85,20 +86,28 @@ pub async fn retrieve_tasks() -> Result<Vec<TaskRequest<String>>, FocusError> {
|
85 | 86 | .map_err(FocusError::UnableToRetrieveTasksHttp)
|
86 | 87 | }
|
87 | 88 |
|
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> { |
89 | 90 | debug!("Answer task with id: {task_id}");
|
90 | 91 | BEAM_CLIENT.put_result(result, &task_id)
|
91 | 92 | .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 | + }) |
93 | 98 | }
|
94 | 99 |
|
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> { |
96 | 101 | let body = body.into();
|
97 | 102 | warn!("Reporting failed task with id {}: {}", task.id, body);
|
98 | 103 | let result = beam_result::perm_failed(CONFIG.beam_app_id_long.clone(), vec![task.from.clone()], task.id, body);
|
99 | 104 | BEAM_CLIENT.put_result(&result, &task.id)
|
100 | 105 | .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 | + }) |
102 | 111 | }
|
103 | 112 |
|
104 | 113 | pub async fn claim_task<T>(task: &TaskRequest<T>) -> Result<bool, FocusError> {
|
|
0 commit comments