Skip to main content

reifydb_sub_task/
factory.rs

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