Attempts to drain the queue by executing all [`EngineTask`]s in-order. If any task returns an error along the way, it is not popped from the queue (in case it must be retried) and the error is returned. Exception: tasks that fail with [`EngineTaskErrorSeverity::Flush`] are popped from the queue before the error is returned. The poisoned task must not be retried in-place — the engine processor wil
(&mut self)
| 569 | /// to popping, mirroring the success path so watch consumers (e.g. the RPC state view) stay |
| 570 | /// in sync. |
| 571 | pub async fn drain(&mut self) -> Result<(), EngineTaskErrors> { |
| 572 | // Drain tasks in order of priority, halting on errors for a retry to be attempted. |
| 573 | while let Some((task, _)) = self.tasks.peek() { |
| 574 | // Execute the task. |
| 575 | let outcome = match task.execute(&mut self.state).await { |
| 576 | Ok(()) => Ok(()), |
| 577 | Err(err) if err.severity() == EngineTaskErrorSeverity::Flush => Err(err), |
| 578 | Err(err) => return Err(err), |
| 579 | }; |
| 580 | |
| 581 | // Update the state and notify the engine actor. |
| 582 | self.state_sender.send_replace(self.state); |
| 583 | |
| 584 | // Pop the task from the queue now that it's been executed. |
| 585 | self.tasks.pop(); |
| 586 | |
| 587 | self.task_queue_length.send_replace(self.tasks.len()); |
| 588 | Metrics::engine_task_queue_depth().set(self.tasks.len() as f64); |
| 589 | |
| 590 | outcome?; |
| 591 | } |
| 592 | |
| 593 | Ok(()) |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | /// An error occurred while attempting to reset the [`Engine`]. |