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    pub use temporalio_protos::*;
23}
24pub mod search_attributes;
25pub mod worker;
26mod workflow_definition;
27
28pub use activity_definition::{ActivityDefinition, ActivityError, UntypedActivity};
29pub use memo::Memo;
30pub use priority::Priority;
31pub use retry_policy::RetryPolicy;
32pub use search_attributes::{
33    SearchAttributeError, SearchAttributeKey, SearchAttributeUpdate, SearchAttributeValue,
34    SearchAttributes, Timestamp,
35};
36pub use worker::WorkerDeploymentVersion;
37pub use workflow_definition::{
38    HasWorkflowDefinition, QueryDefinition, SignalDefinition, UntypedWorkflow, UpdateDefinition,
39    WorkflowDefinition,
40};
41pub use workflow_execution::WorkflowExecution;
42
43#[allow(unused_macros)]
44macro_rules! dbg_panic {
45  ($($arg:tt)*) => {
46      use tracing::error;
47      error!($($arg)*);
48      debug_assert!(false, $($arg)*);
49  };
50}
51#[allow(unused_imports)]
52pub(crate) use dbg_panic;
53
54/// Represents Activity schedule-to-close and start-to-close timeouts for the purposes of specifying
55/// Activity options. Specifying at least one of them is required, but specifying both is also
56/// allowed. Note that this type does not cover all available timeout options for an Activity.
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum ActivityCloseTimeouts {
59    /// Total time the Activity is allowed to run, including retries.
60    ScheduleToClose(Duration),
61    /// Maximum time of a single Activity execution attempt. Note that the Temporal Server doesn't
62    /// detect Worker process failures directly. It relies on this timeout to detect that an
63    /// Activity that didn't complete on time. So this timeout should be as short as the longest
64    /// possible execution of the Activity body. Potentially long running Activities must specify
65    /// `heartbeat_timeout` in options and heartbeat from the activity periodically for timely
66    /// failure detection.
67    StartToClose(Duration),
68    /// Applies both execution-attempt and overall-completion bounds.
69    Both {
70        /// Total time the Activity is allowed to run, including retries.
71        schedule_to_close: Duration,
72        /// Maximum time of a single Activity execution attempt.
73        start_to_close: Duration,
74    },
75}
76
77impl ActivityCloseTimeouts {
78    /// Returns value of [`Self::ScheduleToClose`]  or [`Self::Both::schedule_to_close`].
79    pub fn schedule_to_close(&self) -> Option<Duration> {
80        match self {
81            ActivityCloseTimeouts::ScheduleToClose(schedule_to_close)
82            | ActivityCloseTimeouts::Both {
83                schedule_to_close, ..
84            } => Some(*schedule_to_close),
85            _ => None,
86        }
87    }
88
89    /// Returns value of [`Self::StartToClose`]  or [`Self::Both::start_to_close`].
90    pub fn start_to_close(&self) -> Option<Duration> {
91        match self {
92            ActivityCloseTimeouts::StartToClose(start_to_close)
93            | ActivityCloseTimeouts::Both { start_to_close, .. } => Some(*start_to_close),
94            _ => None,
95        }
96    }
97}