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, MemoValue, MemoValues};
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)]
58#[non_exhaustive]
59pub enum ActivityCloseTimeouts {
60    /// Total time the Activity is allowed to run, including retries.
61    ScheduleToClose(Duration),
62    /// Maximum time of a single Activity execution attempt. Note that the Temporal Server doesn't
63    /// detect Worker process failures directly. It relies on this timeout to detect that an
64    /// Activity that didn't complete on time. So this timeout should be as short as the longest
65    /// possible execution of the Activity body. Potentially long running Activities must specify
66    /// `heartbeat_timeout` in options and heartbeat from the activity periodically for timely
67    /// failure detection.
68    StartToClose(Duration),
69    /// Applies both execution-attempt and overall-completion bounds.
70    ScheduleAndStartToClose {
71        /// Total time the Activity is allowed to run, including retries.
72        schedule_to_close: Duration,
73        /// Maximum time of a single Activity execution attempt.
74        start_to_close: Duration,
75    },
76}
77
78impl ActivityCloseTimeouts {
79    /// Returns value of [`Self::ScheduleToClose`] or
80    /// [`Self::ScheduleAndStartToClose::schedule_to_close`].
81    pub fn schedule_to_close(&self) -> Option<Duration> {
82        match self {
83            ActivityCloseTimeouts::ScheduleToClose(schedule_to_close)
84            | ActivityCloseTimeouts::ScheduleAndStartToClose {
85                schedule_to_close, ..
86            } => Some(*schedule_to_close),
87            _ => None,
88        }
89    }
90
91    /// Returns value of [`Self::StartToClose`] or
92    /// [`Self::ScheduleAndStartToClose::start_to_close`].
93    pub fn start_to_close(&self) -> Option<Duration> {
94        match self {
95            ActivityCloseTimeouts::StartToClose(start_to_close)
96            | ActivityCloseTimeouts::ScheduleAndStartToClose { start_to_close, .. } => {
97                Some(*start_to_close)
98            }
99            _ => None,
100        }
101    }
102}