use std::collections::HashMap;
use std::sync::Mutex;
use futures::future::BoxFuture;
use once_cell::sync::Lazy;
use anyhow::Result;
use crate::job::Job;
pub type HandlerFn = fn(String) -> BoxFuture<'static, Result<Box<dyn Job>>>;
pub static JOB_REGISTRY: Lazy<Mutex<HashMap<&'static str, HandlerFn>>> =
Lazy::new(|| Mutex::new(HashMap::new()));
pub fn register_job(name: &'static str, handler: HandlerFn) {
JOB_REGISTRY.lock().unwrap().insert(name, handler);
}
pub fn get_registered_jobs() -> HashMap<&'static str, HandlerFn> {
JOB_REGISTRY.lock().unwrap().clone()
}
pub fn get_job_handler(name: &str) -> Option<HandlerFn> {
JOB_REGISTRY.lock().unwrap().get(name).copied()
}