lash_core/runtime/
process_work_driver.rs1use std::sync::Arc;
2
3use super::DurableProcessWorker;
4use super::process::ProcessRegistry;
5use crate::PluginError;
6
7#[derive(Clone)]
15pub struct ProcessWorkDriver {
16 registry: Arc<dyn ProcessRegistry>,
17 run_handle: Arc<dyn ProcessRunHandle>,
18}
19
20impl ProcessWorkDriver {
21 pub fn new(registry: Arc<dyn ProcessRegistry>, run_handle: Arc<dyn ProcessRunHandle>) -> Self {
22 Self {
23 registry,
24 run_handle,
25 }
26 }
27
28 pub fn inline(registry: Arc<dyn ProcessRegistry>, worker: DurableProcessWorker) -> Self {
29 Self::new(registry, Arc::new(InlineProcessRunHandle::new(worker)))
30 }
31
32 pub fn process_registry(&self) -> Arc<dyn ProcessRegistry> {
33 Arc::clone(&self.registry)
34 }
35
36 pub async fn claim_and_run_pending(&self, reason: &str) -> Result<(), PluginError> {
37 if let Err(err) = self.run_handle.claim_and_run_pending().await {
38 tracing::warn!("process work drive ({reason}) failed: {err}");
39 return Err(err);
40 }
41 Ok(())
42 }
43}
44
45#[async_trait::async_trait]
51pub trait ProcessRunHandle: Send + Sync {
52 async fn claim_and_run_pending(&self) -> Result<(), PluginError>;
55}
56
57pub struct InlineProcessRunHandle {
63 worker: DurableProcessWorker,
64}
65
66impl InlineProcessRunHandle {
67 pub fn new(worker: DurableProcessWorker) -> Self {
68 Self { worker }
69 }
70}
71
72#[async_trait::async_trait]
73impl ProcessRunHandle for InlineProcessRunHandle {
74 async fn claim_and_run_pending(&self) -> Result<(), PluginError> {
75 self.worker.drive_pending_processes().await
76 }
77}