Skip to main content

qubit_task/service/
task_execution_stats.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use super::task_status::TaskStatus;
11
12/// Count snapshot for a [`TaskExecutionService`](super::TaskExecutionService).
13///
14/// Counters are derived from the service registry and therefore include
15/// terminal task records retained for inspection.
16///
17#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
18pub struct TaskExecutionStats {
19    /// Number of tasks accepted by the service.
20    pub total: usize,
21
22    /// Number of accepted tasks not yet started.
23    pub submitted: usize,
24
25    /// Number of tasks currently running.
26    pub running: usize,
27
28    /// Number of tasks that completed successfully.
29    pub succeeded: usize,
30
31    /// Number of tasks that returned an error.
32    pub failed: usize,
33
34    /// Number of tasks that panicked.
35    pub panicked: usize,
36
37    /// Number of tasks cancelled before start.
38    pub cancelled: usize,
39}
40
41impl TaskExecutionStats {
42    /// Adds one task status to this snapshot.
43    pub(crate) fn add_status(&mut self, status: TaskStatus) {
44        self.total += 1;
45        match status {
46            TaskStatus::Submitted => self.submitted += 1,
47            TaskStatus::Running => self.running += 1,
48            TaskStatus::Succeeded => self.succeeded += 1,
49            TaskStatus::Failed => self.failed += 1,
50            TaskStatus::Panicked => self.panicked += 1,
51            TaskStatus::Cancelled => self.cancelled += 1,
52        }
53    }
54}