Skip to main content

reifydb_sub_task/
factory.rs

1use reifydb_core::util::ioc::IocContainer;
2use reifydb_sub_api::subsystem::{Subsystem, SubsystemFactory};
3use reifydb_transaction::interceptor::builder::InterceptorBuilder;
4use reifydb_type::Result;
5
6use crate::{subsystem::TaskSubsystem, task::ScheduledTask};
7
8/// Configuration for the task scheduler subsystem
9#[derive(Default)]
10pub struct TaskConfig {
11	/// Tasks to register at startup
12	tasks: Vec<ScheduledTask>,
13}
14
15impl TaskConfig {
16	/// Create a new task configuration
17	pub fn new(tasks: Vec<ScheduledTask>) -> Self {
18		Self {
19			tasks,
20		}
21	}
22}
23
24/// Factory for creating TaskSubsystem instances
25pub struct TaskSubsystemFactory {
26	config: TaskConfig,
27}
28
29impl TaskSubsystemFactory {
30	/// Create a new factory with default configuration
31	pub fn new() -> Self {
32		Self {
33			config: TaskConfig::default(),
34		}
35	}
36
37	/// Create a factory with custom configuration
38	pub fn with_config(config: TaskConfig) -> Self {
39		Self {
40			config,
41		}
42	}
43}
44
45impl Default for TaskSubsystemFactory {
46	fn default() -> Self {
47		Self::new()
48	}
49}
50
51impl SubsystemFactory for TaskSubsystemFactory {
52	fn provide_interceptors(&self, builder: InterceptorBuilder, _ioc: &IocContainer) -> InterceptorBuilder {
53		// Task subsystem doesn't need any special interceptors
54		builder
55	}
56
57	fn create(self: Box<Self>, ioc: &IocContainer) -> Result<Box<dyn Subsystem>> {
58		Ok(Box::new(TaskSubsystem::new(ioc, self.config.tasks)))
59	}
60}