Skip to main content

qubit_executor/hook/
logging_task_hook.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 crate::{
11    TaskStatus,
12    hook::{
13        TaskHook,
14        TaskId,
15    },
16    service::SubmissionError,
17};
18
19/// Task hook that writes lifecycle events through the `log` facade.
20#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
21pub struct LoggingTaskHook;
22
23impl TaskHook for LoggingTaskHook {
24    /// Logs task acceptance.
25    #[inline]
26    fn on_accepted(&self, task_id: TaskId) {
27        log::debug!("task {} accepted", task_id.get());
28    }
29
30    /// Logs task rejection.
31    #[inline]
32    fn on_rejected(&self, error: &SubmissionError) {
33        log::debug!("task rejected: {error}");
34    }
35
36    /// Logs task start.
37    #[inline]
38    fn on_started(&self, task_id: TaskId) {
39        log::debug!("task {} started", task_id.get());
40    }
41
42    /// Logs task completion.
43    #[inline]
44    fn on_finished(&self, task_id: TaskId, status: TaskStatus) {
45        log::debug!("task {} finished with status {:?}", task_id.get(), status);
46    }
47}