Skip to main content

reifydb_sub_task/
registry.rs

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