Skip to main content

temporalio_common_wasm/
lib.rs

1#![warn(missing_docs)] // error if there are missing docs
2
3//! This crate contains the shared definitions and serialization/proto surface needed by the
4//! workflow authoring APIs, including WASM-targeted builds.
5
6#[allow(unused_imports)] // Not used by all flag combinations, which is fine.
7#[macro_use]
8extern crate tracing;
9
10use std::time::Duration;
11
12mod activity_definition;
13pub mod data_converters;
14pub mod error;
15mod memo;
16mod priority;
17mod retry_policy;
18mod workflow_execution;
19pub mod protos {
20    //! Protobuf definitions re-exported from `temporalio-protos`.
21    //!
22    //! Because this module re-exports generated types, updating it might include breaking changes.
23    pub use temporalio_protos::*;
24}
25pub mod search_attributes;
26pub mod worker;
27mod workflow_definition;
28
29pub use activity_definition::{ActivityDefinition, ActivityError, UntypedActivity};
30pub use memo::{Memo, MemoValue, MemoValues};
31pub use priority::Priority;
32pub use retry_policy::RetryPolicy;
33pub use search_attributes::{
34    SearchAttributeError, SearchAttributeKey, SearchAttributeUpdate, SearchAttributeValue,
35    SearchAttributes, Timestamp,
36};
37pub use worker::WorkerDeploymentVersion;
38pub use workflow_definition::{
39    HasWorkflowDefinition, QueryDefinition, SignalDefinition, UntypedWorkflow, UpdateDefinition,
40    WorkflowDefinition,
41};
42pub use workflow_execution::WorkflowExecution;
43
44#[allow(unused_macros)]
45macro_rules! dbg_panic {
46  ($($arg:tt)*) => {
47      use tracing::error;
48      error!($($arg)*);
49      debug_assert!(false, $($arg)*);
50  };
51}
52#[allow(unused_imports)]
53pub(crate) use dbg_panic;
54
55/// Represents Activity schedule-to-close and start-to-close timeouts for the purposes of specifying
56/// Activity options. Specifying at least one of them is required, but specifying both is also
57/// allowed. Note that this type does not cover all available timeout options for an Activity.
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59#[non_exhaustive]
60pub enum ActivityCloseTimeouts {
61    /// Total time the Activity is allowed to run, including retries.
62    ScheduleToClose(Duration),
63    /// Maximum time of a single Activity execution attempt. Note that the Temporal Server doesn't
64    /// detect Worker process failures directly. It relies on this timeout to detect that an
65    /// Activity that didn't complete on time. So this timeout should be as short as the longest
66    /// possible execution of the Activity body. Potentially long running Activities must specify
67    /// `heartbeat_timeout` in options and heartbeat from the activity periodically for timely
68    /// failure detection.
69    StartToClose(Duration),
70    /// Applies both execution-attempt and overall-completion bounds.
71    ScheduleAndStartToClose {
72        /// Total time the Activity is allowed to run, including retries.
73        schedule_to_close: Duration,
74        /// Maximum time of a single Activity execution attempt.
75        start_to_close: Duration,
76    },
77}
78
79impl ActivityCloseTimeouts {
80    /// Returns value of [`Self::ScheduleToClose`] or
81    /// [`Self::ScheduleAndStartToClose::schedule_to_close`].
82    pub fn schedule_to_close(&self) -> Option<Duration> {
83        match self {
84            ActivityCloseTimeouts::ScheduleToClose(schedule_to_close)
85            | ActivityCloseTimeouts::ScheduleAndStartToClose {
86                schedule_to_close, ..
87            } => Some(*schedule_to_close),
88            _ => None,
89        }
90    }
91
92    /// Returns value of [`Self::StartToClose`] or
93    /// [`Self::ScheduleAndStartToClose::start_to_close`].
94    pub fn start_to_close(&self) -> Option<Duration> {
95        match self {
96            ActivityCloseTimeouts::StartToClose(start_to_close)
97            | ActivityCloseTimeouts::ScheduleAndStartToClose { start_to_close, .. } => {
98                Some(*start_to_close)
99            }
100            _ => None,
101        }
102    }
103}