Skip to main content

reifydb_sub_task/
registry.rs

1use std::{sync::Arc, time::Instant};
2
3use dashmap::DashMap;
4
5use crate::task::{ScheduledTask, TaskId};
6
7/// Entry in the task registry tracking execution state
8#[derive(Debug, Clone)]
9pub struct TaskEntry {
10	/// The task definition
11	pub task: Arc<ScheduledTask>,
12	/// When the task should next execute
13	pub next_execution: Instant,
14}
15
16/// Thread-safe registry of scheduled tasks
17pub type TaskRegistry = Arc<DashMap<TaskId, TaskEntry>>;
18
19/// Information about a task for status queries
20#[derive(Debug, Clone)]
21pub struct TaskInfo {
22	pub id: TaskId,
23	pub name: String,
24	pub next_execution: Instant,
25}
26
27impl TaskInfo {
28	pub fn from_entry(id: TaskId, entry: &TaskEntry) -> Self {
29		Self {
30			id,
31			name: entry.task.name.clone(),
32			next_execution: entry.next_execution,
33		}
34	}
35}