diff --git a/judger/src/agent/platform/mod.rs b/judger/src/agent/platform/mod.rs index c42b6bf..8ccc159 100644 --- a/judger/src/agent/platform/mod.rs +++ b/judger/src/agent/platform/mod.rs @@ -12,7 +12,7 @@ impl PlatformClient { } } - pub async fn pick_task(&self) -> Result { + pub async fn pick_task(&self) -> Result, anyhow::Error> { pick_task(&self.client).await } @@ -45,7 +45,7 @@ struct PickTaskResponse { task: JudgeTask, } -async fn pick_task(client: &HttpClient) -> Result { +async fn pick_task(client: &HttpClient) -> Result, anyhow::Error> { let pick_url = "api/v1/judge/task/pick"; let body = PickTaskBody { consumer: "".to_string(), @@ -53,10 +53,14 @@ async fn pick_task(client: &HttpClient) -> Result { let response = client.post(pick_url.to_string()).json(&body).send().await?; match response.status() { - reqwest::StatusCode::OK => Ok(response.json::().await?.task), + reqwest::StatusCode::OK => Ok(Some(response.json::().await?.task)), + reqwest::StatusCode::NO_CONTENT => Ok(None), _ => { log::error!("Failed to pick task: {:?}", response); - Err(anyhow::anyhow!("Queue is empty")) + Err(anyhow::anyhow!(format!( + "Failed to pick task: {:?}", + response + ))) } } } diff --git a/judger/src/worker/mod.rs b/judger/src/worker/mod.rs index b7424bc..832cb2b 100644 --- a/judger/src/worker/mod.rs +++ b/judger/src/worker/mod.rs @@ -62,7 +62,11 @@ impl JudgeWorker { loop { interval.tick().await; match platform_client.pick_task().await { - Ok(task) => { + Ok(maybe_task) => { + if maybe_task.is_none() { + continue; + } + let task = maybe_task.unwrap(); log::info!("Received task: {:?}", task); match self.run_judge( task.problem_slug.clone(),