11//! Contains types for activity definitions, used by the code generated by the macros for defining
22//! activities, or directly by users targeting activities in other languages.
33
4- use crate :: data_converters:: { TemporalDeserializable , TemporalSerializable } ;
4+ use crate :: {
5+ data_converters:: { TemporalDeserializable , TemporalSerializable } ,
6+ protos:: temporal:: api:: common:: v1:: Payload ,
7+ } ;
8+ use std:: time:: Duration ;
59
610/// Implement on a marker struct to define an activity.
711///
@@ -18,3 +22,46 @@ pub trait ActivityDefinition {
1822 where
1923 Self : Sized ;
2024}
25+
26+ /// Returned as errors from activity functions.
27+ #[ derive( Debug ) ]
28+ pub enum ActivityError {
29+ /// This error can be returned from activities to allow the explicit configuration of certain
30+ /// error properties. It's also the default error type that arbitrary errors will be converted
31+ /// into.
32+ Retryable {
33+ /// The underlying error
34+ source : Box < dyn std:: error:: Error + Send + Sync + ' static > ,
35+ /// If specified, the next retry (if there is one) will occur after this delay
36+ explicit_delay : Option < Duration > ,
37+ } ,
38+ /// Return this error to indicate your activity is cancelling
39+ Cancelled {
40+ /// Some data to save as the cancellation reason
41+ details : Option < Payload > ,
42+ } ,
43+ /// Return this error to indicate that the activity should not be retried.
44+ NonRetryable ( Box < dyn std:: error:: Error + Send + Sync + ' static > ) ,
45+ /// Return this error to indicate that the activity will be completed outside of this activity
46+ /// definition, by an external client.
47+ WillCompleteAsync ,
48+ }
49+
50+ impl ActivityError {
51+ /// Construct a cancelled error without details
52+ pub fn cancelled ( ) -> Self {
53+ Self :: Cancelled { details : None }
54+ }
55+ }
56+
57+ impl < E > From < E > for ActivityError
58+ where
59+ E : Into < anyhow:: Error > ,
60+ {
61+ fn from ( source : E ) -> Self {
62+ Self :: Retryable {
63+ source : source. into ( ) . into_boxed_dyn_error ( ) ,
64+ explicit_delay : None ,
65+ }
66+ }
67+ }
0 commit comments