1use std::fmt::{Display, Formatter, Result as FmtResult};
4use valuable::Valuable;
5
6#[derive(Copy, Clone, Debug, Hash, PartialOrd, Ord, PartialEq, Eq, Valuable)]
8#[repr(transparent)]
9pub struct ThreadOrTokioTaskId(pub u64);
10
11impl Display for ThreadOrTokioTaskId {
12 fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
13 write!(fmt, "{}", self.0)
14 }
15}
16
17#[derive(Copy, Clone, Debug, Hash, PartialOrd, Ord, PartialEq, Eq, Valuable)]
19#[repr(transparent)]
20pub struct LisaTaskId(pub u64);
21
22impl Display for LisaTaskId {
23 fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
24 write!(fmt, "{}", self.0)
25 }
26}
27
28pub type GloballyUniqueTaskId = (ThreadOrTokioTaskId, LisaTaskId);
30
31#[derive(Clone, Debug, PartialEq, Eq, Valuable)]
33pub enum LisaTaskStatus {
34 Inactive,
36 Running(Option<String>),
39 Waiting(Option<String>),
42}
43
44impl Display for LisaTaskStatus {
45 fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
46 write!(
47 fmt,
48 "{}",
49 match self {
50 LisaTaskStatus::Inactive => {
51 "inactive".to_owned()
52 }
53 LisaTaskStatus::Running(reason) =>
54 if let Some(real_reason) = reason {
55 format!("running/doing={real_reason}")
56 } else {
57 "running".to_owned()
58 },
59 LisaTaskStatus::Waiting(reason) =>
60 if let Some(real_reason) = reason {
61 format!("waiting/on={real_reason}")
62 } else {
63 "waiting".to_owned()
64 },
65 },
66 )
67 }
68}
69
70#[derive(Clone, Debug, PartialEq, Eq, Valuable)]
72pub enum TaskEvent {
73 TaskStart(ThreadOrTokioTaskId, LisaTaskId, String, LisaTaskStatus),
75 TaskStatusUpdate(ThreadOrTokioTaskId, LisaTaskId, LisaTaskStatus),
77 TaskEnd(ThreadOrTokioTaskId, LisaTaskId),
79}
80
81pub trait TaskEventLogProvider: Send + Sync {
83 #[must_use]
87 fn new_events(&self) -> Vec<TaskEvent>;
88}