dapr_durabletask/task/
activity_context.rs1use crate::api::PropagatedHistory;
2
3pub struct ActivityContext {
5 pub(crate) orchestration_id: String,
6 pub(crate) task_id: i32,
7 pub(crate) task_execution_id: String,
8 pub(crate) propagated_history: Option<PropagatedHistory>,
9}
10
11impl ActivityContext {
12 pub fn new(orchestration_id: String, task_id: i32, task_execution_id: String) -> Self {
13 Self {
14 orchestration_id,
15 task_id,
16 task_execution_id,
17 propagated_history: None,
18 }
19 }
20
21 pub fn with_propagated_history(mut self, history: Option<PropagatedHistory>) -> Self {
24 self.propagated_history = history;
25 self
26 }
27
28 pub fn orchestration_id(&self) -> &str {
29 &self.orchestration_id
30 }
31
32 pub fn task_id(&self) -> i32 {
33 self.task_id
34 }
35
36 pub fn task_execution_id(&self) -> &str {
42 &self.task_execution_id
43 }
44
45 pub fn propagated_history(&self) -> Option<&PropagatedHistory> {
48 self.propagated_history.as_ref()
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_activity_context() {
58 let ctx = ActivityContext::new("inst-1".to_string(), 42, "exec-abc".to_string());
59 assert_eq!(ctx.orchestration_id(), "inst-1");
60 assert_eq!(ctx.task_id(), 42);
61 assert_eq!(ctx.task_execution_id(), "exec-abc");
62 }
63}