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