Skip to main content

bpm_engine_worker_sdk/
handler.rs

1//! TaskHandler trait and TaskContext (design §1). User implements TaskHandler; runtime passes TaskContext.
2
3use async_trait::async_trait;
4
5use crate::types::{ExternalTask, TaskResult};
6
7/// Context passed to the handler; placeholder for extend_lock etc. (Phase 2).
8#[derive(Debug, Clone)]
9pub struct TaskContext {
10    #[allow(dead_code)]
11    pub(crate) worker_id: String,
12    #[allow(dead_code)]
13    pub(crate) task_id: String,
14}
15
16impl TaskContext {
17    pub fn new(worker_id: String, task_id: String) -> Self {
18        Self { worker_id, task_id }
19    }
20}
21
22/// User implements this to handle tasks (design §1).
23#[async_trait]
24pub trait TaskHandler: Send + Sync {
25    fn task_type(&self) -> &str;
26
27    async fn handle(&self, task: ExternalTask, ctx: TaskContext) -> TaskResult;
28}