shinyframework_application 0.1.2

Shiny Application
Documentation
use crate::Module;
use shiny_common::context::Context;
use shiny_common::error::ServiceError;
use shiny_jobs::Job;
use std::collections::HashMap;
use std::sync::Arc;

pub struct TestApplication {
    jobs: HashMap<String, Arc<dyn Job>>,
}

impl TestApplication {
    pub fn new<TClients, TModule>(clients: TClients, module: TModule) -> Self
    where
        TModule: Module<Clients = TClients>,
    {
        let controllers = module.create(clients);

        TestApplication {
            jobs: controllers.job.take_jobs().into_iter().collect(),
        }
    }

    pub async fn run_job(&self, name: &str, context: &mut Context) -> Result<(), ServiceError> {
        let Some(job) = self.jobs.get(name) else {
            panic!("job `{name}` does not exists")
        };
        job.execute(context).await?;
        Ok(())
    }
}