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)
| 530 | /// to popping, mirroring the success path so watch consumers (e.g. the RPC state view) stay |
| 531 | /// in sync. |
| 532 | pub async fn drain(&mut self) -> Result<(), EngineTaskErrors> { |
| 533 | // Drain tasks in order of priority, halting on errors for a retry to be attempted. |
| 534 | while let Some((task, _)) = self.tasks.peek() { |
| 535 | // Execute the task. |
| 536 | let outcome = match task.execute(&mut self.state).await { |
| 537 | Ok(()) => Ok(()), |
| 538 | Err(err) if err.severity() == EngineTaskErrorSeverity::Flush => Err(err), |
| 539 | Err(err) => return Err(err), |
| 540 | }; |
| 541 | |
| 542 | // Update the state and notify the engine actor. |
| 543 | self.state_sender.send_replace(self.state); |
| 544 | |
| 545 | // Pop the task from the queue now that it's been executed. |
| 546 | self.tasks.pop(); |
| 547 | |
| 548 | self.task_queue_length.send_replace(self.tasks.len()); |
| 549 | Metrics::engine_task_queue_depth().set(self.tasks.len() as f64); |
| 550 | |
| 551 | outcome?; |
| 552 | } |
| 553 | |
| 554 | Ok(()) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | /// An error occurred while attempting to reset the [`Engine`]. |
no test coverage detected