diff --git a/src/api.rs b/src/api.rs index 030753d..b606f4d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -169,6 +169,10 @@ impl Work { matches!(self, Work::Analysis { .. }) } + pub fn is_move(&self) -> bool { + matches!(self, Work::Move { .. }) + } + pub fn multipv(&self) -> NonZeroU8 { match *self { Work::Analysis { multipv, .. } => multipv, diff --git a/src/queue.rs b/src/queue.rs index 1c022e3..892e80e 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -126,7 +126,7 @@ struct QueueState { cores: NonZeroUsize, incoming: VecDeque, pending: HashMap, - move_submissions: VecDeque, + move_submissions: VecDeque, stats_recorder: StatsRecorder, logger: Logger, } @@ -291,9 +291,12 @@ impl QueueState { completed.into_analysis(), ); } - Work::Move { .. } => { + Work::Move { id, .. } => { self.logger.debug(&log); - self.move_submissions.push_back(completed); + self.move_submissions.push_back(MoveSubmission { + batch_id: id, + best_move: completed.into_best_move(), + }); queue.move_submitted(); } } @@ -315,6 +318,12 @@ impl QueueState { } } +#[derive(Debug)] +struct MoveSubmission { + batch_id: BatchId, + best_move: Option, +} + #[derive(Debug)] enum QueueMessage { Pull { callback: oneshot::Sender }, @@ -380,11 +389,13 @@ impl QueueActor { } async fn handle_acquired_response_body(&mut self, body: AcquireResponseBody) { + let batch_id = body.work.id(); let context = ProgressAt { - batch_id: body.work.id(), + batch_id, batch_url: body.batch_url(self.api.endpoint()), position_index: None, }; + let is_move = body.work.is_move(); match IncomingBatch::from_acquired(self.api.endpoint(), body) { Ok(incoming) => { @@ -400,6 +411,15 @@ impl QueueActor { completed.into_analysis(), ); } + Err(err) if is_move => { + self.logger + .warn(&format!("Invalid move request {context}: {err:?}")); + let mut state = self.state.lock().await; + state.move_submissions.push_back(MoveSubmission { + batch_id, + best_move: None, + }); + } Err(err) => { self.logger .warn(&format!("Ignoring invalid batch {context}: {err:?}")); @@ -424,7 +444,7 @@ impl QueueActor { if let Some(completed) = next { if let Some(Acquired::Accepted(body)) = self .api - .submit_move_and_acquire(completed.work.id(), completed.into_best_move()) + .submit_move_and_acquire(completed.batch_id, completed.best_move) .await { self.handle_acquired_response_body(body).await;