Skip to main content

a3s_flow/worker/
task.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::model::JsonValue;
5
6/// Queueable unit of workflow engine work.
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8#[serde(tag = "type", rename_all = "snake_case")]
9pub enum FlowTask {
10    DriveRun {
11        run_id: String,
12    },
13    ResumeWait {
14        run_id: String,
15        wait_id: String,
16    },
17    ResumeHook {
18        run_id: String,
19        hook_id: String,
20        payload: JsonValue,
21    },
22    ResumeHookByToken {
23        token: String,
24        payload: JsonValue,
25    },
26    DisposeHook {
27        run_id: String,
28        hook_id: String,
29    },
30    DisposeHookByToken {
31        token: String,
32    },
33    ResumeDueWaits {
34        now: DateTime<Utc>,
35    },
36    ResumeDueRetries {
37        now: DateTime<Utc>,
38    },
39}
40
41/// Result of handling one queued [`FlowTask`].
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
43pub struct FlowTaskOutcome {
44    pub task: FlowTask,
45    pub run_ids: Vec<String>,
46    pub resumed_waits: Vec<(String, String)>,
47    pub resumed_retries: Vec<(String, String)>,
48    pub resumed_hook: Option<(String, String)>,
49    #[serde(default)]
50    pub disposed_hook: Option<(String, String)>,
51}
52
53impl FlowTaskOutcome {
54    pub(super) fn new(task: FlowTask) -> Self {
55        Self {
56            task,
57            run_ids: Vec::new(),
58            resumed_waits: Vec::new(),
59            resumed_retries: Vec::new(),
60            resumed_hook: None,
61            disposed_hook: None,
62        }
63    }
64}
65
66/// Leased task returned by a queue worker before acknowledgement.
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
68pub struct FlowTaskLease {
69    pub lease_id: String,
70    pub task: FlowTask,
71}
72
73/// Task moved out of inflight dispatch after exceeding a local lease policy.
74#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
75pub struct LocalFileDeadLetteredTask {
76    pub lease_id: String,
77    pub task: FlowTask,
78    pub reason: String,
79    pub dead_lettered_at: DateTime<Utc>,
80}
81
82/// Task moved out of Postgres inflight dispatch after exceeding a lease policy.
83#[cfg(feature = "postgres")]
84#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
85pub struct PostgresDeadLetteredTask {
86    pub lease_id: String,
87    pub task: FlowTask,
88    pub reason: String,
89    pub dead_lettered_at: DateTime<Utc>,
90}