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