1use std::collections::HashMap;
4use std::sync::Mutex;
5use futures::future::BoxFuture;
6use once_cell::sync::Lazy;
7use anyhow::Result;
8use crate::job::Job;
9
10pub type HandlerFn = fn(String) -> BoxFuture<'static, Result<Box<dyn Job>>>;
13
14pub static JOB_REGISTRY: Lazy<Mutex<HashMap<&'static str, HandlerFn>>> =
16 Lazy::new(|| Mutex::new(HashMap::new()));
17
18pub fn register_job(name: &'static str, handler: HandlerFn) {
20 JOB_REGISTRY.lock().unwrap().insert(name, handler);
21}
22
23pub fn get_registered_jobs() -> HashMap<&'static str, HandlerFn> {
25 JOB_REGISTRY.lock().unwrap().clone()
26}
27
28pub fn get_job_handler(name: &str) -> Option<HandlerFn> {
30 JOB_REGISTRY.lock().unwrap().get(name).copied()
31}