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