Skip to content

Commit fffb25d

Browse files
chore: update Rust docs to reflect 0.7.0 release (#5132)
* chore: update Rust docs to reflect 0.7.0 release * self review --------- Co-authored-by: Milecia McG <47196133+flippedcoder@users.noreply.github.com>
1 parent cee8087 commit fffb25d

14 files changed

Lines changed: 407 additions & 435 deletions

docs/develop/rust/activities/basics.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct SleeperActivities {
7272
#[activities]
7373
impl SleeperActivities {
7474
#[activity]
75-
async fn sleeper(
75+
pub async fn sleeper(
7676
self: Arc<Self>,
7777
ctx: ActivityContext,
7878
_: String,
@@ -144,7 +144,9 @@ impl MyActivities {
144144

145145
// If an error should not be retried
146146
if input.len() > 1000000 {
147-
return Err(ApplicationFailure::non_retryable("Input too large").into());
147+
return Err(
148+
ApplicationFailure::non_retryable("Input too large").into(),
149+
);
148150
}
149151

150152
let result = ProcessedData {

docs/develop/rust/activities/execution.mdx

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Be mindful of the size of data passed to and from Activities. Otherwise, there a
2626

2727
To spawn an Activity Execution, use the Workflow context’s Activity execution APIs within your Workflow code.
2828

29-
In Rust, Activities are typically executed using `ctx.start_activity(...)`, which returns a `Future` that can be awaited.
29+
In Rust, Activities are typically executed using `ctx.execute_activity(...)`, which returns a `Future` that can be awaited.
3030

3131
```rust
3232
#[workflow_methods]
@@ -35,11 +35,13 @@ impl GreetingWorkflow {
3535
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
3636
let name = ctx.state(|s| s.name.clone());
3737
// Execute an activity
38-
let greeting = ctx.start_activity(
39-
MyActivities::greet,
40-
name,
41-
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
42-
).await?;
38+
let greeting = ctx
39+
.execute_activity(
40+
MyActivities::greet,
41+
name,
42+
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
43+
)
44+
.await?;
4345

4446
println!("{}", greeting);
4547

@@ -74,11 +76,13 @@ impl GreetingWorkflow {
7476
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
7577
let name = ctx.state(|s| s.name.clone());
7678
// Execute an activity
77-
let greeting = ctx.start_activity(
78-
MyActivities::greet,
79-
name,
80-
ActivityOptions::schedule_to_close_timeout(Duration::from_secs(30))
81-
).await?;
79+
let greeting = ctx
80+
.execute_activity(
81+
MyActivities::greet,
82+
name,
83+
ActivityOptions::schedule_to_close_timeout(Duration::from_secs(30)),
84+
)
85+
.await?;
8286

8387
println!("{}", greeting);
8488
Ok(greeting)
@@ -106,11 +110,13 @@ impl GreetingWorkflow {
106110
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
107111
let name = ctx.state(|s| s.name.clone());
108112
// Execute an activity
109-
let greeting = ctx.start_activity(
110-
MyActivities::greet,
111-
name,
112-
ActivityOptions::start_to_close_timeout(Duration::from_secs(30))
113-
).await?;
113+
let greeting = ctx
114+
.execute_activity(
115+
MyActivities::greet,
116+
name,
117+
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
118+
)
119+
.await?;
114120

115121
println!("{}", greeting);
116122
Ok(greeting)
@@ -127,20 +133,22 @@ use temporalio_sdk::workflows::join;
127133
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
128134
let name = ctx.state(|s| s.name.clone());
129135
// Execute an activity
130-
let greeting = ctx.start_activity(
136+
let greeting = ctx.execute_activity(
131137
MyActivities::greet,
132138
name,
133-
ActivityOptions::start_to_close_timeout(Duration::from_secs(30))
139+
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
134140
);
135141

136-
let language = ctx.start_activity(
142+
let language = ctx.execute_activity(
137143
MyActivities::call_greeting_service,
138144
ActivityLanguages::English,
139-
ActivityOptions::start_to_close_timeout(Duration::from_secs(30))
145+
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
140146
);
141147

142148
// Run in parallel
143149
let (greeting_res, language_res) = join!(greeting, language);
150+
151+
Ok(format!("{} ({})", greeting_res?, language_res?))
144152
}
145153
```
146154

docs/develop/rust/activities/timeouts.mdx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ Available timeout fields include:
3838
- `start_to_close_timeout`
3939

4040
```rust
41-
let greeting = ctx.start_activity(
41+
let greeting = ctx.execute_activity(
4242
MyActivities::greet,
4343
name,
44-
ActivityOptions::start_to_close_timeout(Duration::from_secs(30))
45-
);
46-
````
44+
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
45+
).await?;
46+
```
4747

4848
### Set an Activity Retry Policy {/* #activity-retries */}
4949

@@ -52,20 +52,21 @@ A Retry Policy works together with timeouts to provide fine-grained control over
5252
In Rust, configure the Retry Policy as part of the Activity options when scheduling the Activity from Workflow code. Because the Rust SDK API is still evolving, treat the following as representative of the current style rather than a guaranteed stable surface.
5353

5454
```rust
55-
let language = ctx.start_activity(
55+
let language = ctx.execute_activity(
5656
MyActivities::call_greeting_service,
5757
ActivityLanguages::English,
5858
ActivityOptions::with_start_to_close_timeout(Duration::from_secs(30))
5959
.retry_policy(
60-
RetryPolicy {
61-
initial_interval: Some(prost_dur!(from_secs(10))),
62-
backoff_coefficient: 2.0,
63-
maximum_interval: Some(prost_dur!(from_secs(100))),
64-
maximum_attempts: 5,
65-
non_retryable_error_types: vec!["NonRetryableError".to_string()]
66-
}
67-
).build()
68-
);
60+
RetryPolicy::builder()
61+
.initial_interval(Duration::from_secs(10))
62+
.backoff_coefficient(2.0)
63+
.maximum_interval(Duration::from_secs(100))
64+
.maximum_attempts(5)
65+
.non_retryable_error_types(["NonRetryableError"])
66+
.build(),
67+
)
68+
.build(),
69+
).await?;
6970
```
7071

7172
### Override the retry interval with `explicit_delay` {/* #next-retry-delay */}
@@ -75,12 +76,12 @@ To override the next retry interval set by the current policy, return a failure
7576
For example, you can increase the delay linearly with each attempt instead of using the exponential backoff defined by a backoff coefficient:
7677

7778
```rust
78-
use temporalio_macros::{activities};
79+
use temporalio_macros::activities;
7980
use temporalio_sdk::{
8081
ApplicationFailure,
8182
activities::{ActivityContext, ActivityError},
8283
};
83-
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
84+
use std::sync::atomic::AtomicUsize;
8485

8586
struct TestGreetActivities {
8687
counter: AtomicUsize,
@@ -114,7 +115,8 @@ To heartbeat an Activity in Rust, call the heartbeat API from inside the Activit
114115

115116
```rust
116117
pub async fn greet(ctx: ActivityContext, name: String) -> Result<String, ActivityError> {
117-
ctx.record_heartbeat(vec!["greet activity started".into()]);
118+
ctx.record_heartbeat("greet activity started".to_string())
119+
.await?;
118120

119121
if name == "ziggy" {
120122
return Err(ApplicationFailure::new("Ziggy is not a valid name").into());
@@ -129,11 +131,11 @@ pub async fn greet(ctx: ActivityContext, name: String) -> Result<String, Activit
129131
A [Heartbeat Timeout](/encyclopedia/detecting-activity-failures#heartbeat-timeout) works together with Activity heartbeats and sets the maximum time allowed between heartbeats. Configure it as part of the Activity options when scheduling the Activity.
130132

131133
```rust
132-
let language = ctx.start_activity(
134+
let language = ctx.execute_activity(
133135
MyActivities::call_greeting_service,
134136
ActivityLanguages::English,
135137
ActivityOptions::with_start_to_close_timeout(Duration::from_secs(30))
136138
.heartbeat_timeout(Duration::from_secs(5))
137-
.build()
138-
);
139+
.build(),
140+
);
139141
```

0 commit comments

Comments
 (0)