feat(rust): rust sdk docs#4412
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📖 Docs PR preview links
|
658bb46 to
5599ed2
Compare
5599ed2 to
8ed93c7
Compare
adb4a7a to
3d673be
Compare
3d673be to
d6eb0bd
Compare
d6eb0bd to
bcd3c34
Compare
2cb46fa to
de03821
Compare
| let connection_options = | ||
| ConnectionOptions::new(Url::from_str("http://localhost:7233")?).build(); |
There was a problem hiding this comment.
It might make sense to funnel users towards envconfig:
https://github.com/temporalio/sdk-core/blob/00d3888adc36d4fab36cca3fdd8426c199ab669d/crates/sdk/examples/hello_world/worker.rs#L18
|
|
||
| **How to define Activity parameters using the Temporal Rust SDK.** | ||
|
|
||
| There is no explicit limit to the total number of parameters that an [Activity Definition](/activity-definition) may support. However, there is a limit to the total size of the data that ends up encoded into a gRPC message Payload. |
There was a problem hiding this comment.
For Rust we actually have a hard cap of 6 parameters for activities.
|
|
||
| We recommend that you use a single struct as an argument that wraps all the application data passed to Activities. This way you can change what data is passed to the Activity without breaking the function signature. | ||
|
|
||
| Activity parameters must be serializable and deserializable using serde. Use `#[derive(Serialize, Deserialize)]` on your data types: |
There was a problem hiding this comment.
This isn't a hard requirement, but implementing the serde traits are the easiest way to ensure they work. If they have a protobuf message they can leverage ProstSerializable for encoding without implementing the serde traits.
I am actively working on improving the ergonomics of using protobuf instead of serde, so I don't have a good sample yet.
bd0fa79 to
a777017
Compare
Sushisource
left a comment
There was a problem hiding this comment.
I think we've got to figure out a way to make sure we're actually compiling code snippets going directly into docs, because a lot of these would fail to compile.
Super happy to see the progress here, but, we need some automated gates around this AI-generated code otherwise we're going to frustrate a lot of users.
| - Be `async` (return a future) | ||
| - Take `ActivityContext` as the first parameter | ||
| - Return `Result<T, ActivityError>` where `T` is the return type | ||
| - Be `pub` (public) | ||
|
|
There was a problem hiding this comment.
This doesn't mention activities that can take Arc<Self> and be registered using an instance. We should have an example of that somewhere as well.
| ### Define Activity return values {#activity-return-values} | ||
|
|
||
| **How to define Activity return values using the Temporal Rust SDK.** |
There was a problem hiding this comment.
I'd probably just combine this and the above section since they're really dealing with the same concept.
| Activities return `Result<T, ActivityError>` with different error types for different failure scenarios: | ||
|
|
||
| - **`ActivityError::Retryable`** - Transient failure that should be retried according to the Activity's retry policy | ||
| - **`ActivityError::NonRetryable`** - Permanent failure that will not be retried | ||
| - **`ActivityError::Cancelled`** - Activity was cancelled by the Workflow |
There was a problem hiding this comment.
This section should probably refer to what the default behavior is for errors bubbled up via ?
(Which I believe is to convert them into a Retryable activity error)
| start_to_close_timeout: Some(Duration::from_secs(10)), | ||
| // How long to wait before retrying a failed Activity | ||
| schedule_to_close_timeout: Some(Duration::from_secs(60)), |
There was a problem hiding this comment.
Activity options changed recently so that we require one or both of these timeouts at the type level, this file will need some updates
| // Wait for both to complete | ||
| let result1 = future1.await?; | ||
| let result2 = future2.await?; |
There was a problem hiding this comment.
This should use our join! helper
| // How many Workflow tasks to poll concurrently | ||
| .max_concurrent_workflow_task_polls(10) | ||
| // How many Activity tasks to poll concurrently | ||
| .max_concurrent_activity_task_polls(10) | ||
| // How long to wait for tasks from the service | ||
| .pollers_config(PollerConfig { | ||
| max_tasks_per_poll: 100, | ||
| ..Default::default() | ||
| }) |
There was a problem hiding this comment.
All these options are fabricated. xxx_task_poller_behavior is the actual name
|
|
||
| ## Scale Workers Horizontally {#scale-workers} | ||
|
|
||
| You can run multiple Worker processes on different machines, all listening to the same Task Queue: |
There was a problem hiding this comment.
You could but there's essentially zero reason to do so. We should remove this section.
| tokio::select! { | ||
| _ = worker.run() => println!("Worker stopped"), | ||
| _ = signal::ctrl_c() => { | ||
| println!("Received shutdown signal, gracefully shutting down..."); | ||
| // Worker will complete in-flight tasks | ||
| } | ||
| } |
There was a problem hiding this comment.
This will cause us to just stop caring about the worker's run function, which is not what we want, and will mean shutdown is not graceful.
This code needs to instead spawn a task that listens for ctrl_c, and if received, calls the function returned by shutdown_handle() on the worker.
Then, run is always awaited until conclusion
|
|
||
| ## Define Workflow parameters {#workflow-parameters} | ||
|
|
||
| Temporal Workflows may have any number of custom parameters. However, we strongly recommend that objects are used as parameters, so that the object's individual fields may be altered without breaking the signature of the Workflow. All Workflow Definition parameters must be serializable. |
There was a problem hiding this comment.
| Temporal Workflows may have any number of custom parameters. However, we strongly recommend that objects are used as parameters, so that the object's individual fields may be altered without breaking the signature of the Workflow. All Workflow Definition parameters must be serializable. | |
| Temporal Workflows may have any number of custom parameters. However, we strongly recommend that structs are used as parameters, so that the object's individual fields may be altered without breaking the signature of the Workflow. All Workflow Definition parameters must be serializable. |
| ..Default::default() | ||
| }; | ||
|
|
||
| let started = ctx.child_workflow(child_opts).start().await.into_started().unwrap(); |
There was a problem hiding this comment.
Neither start() nor into_started() exist
Co-authored-by: Chris Olszewski <chrisdolszewski@gmail.com>
1120fd3 to
f03f68d
Compare
What does this PR do?
This adds the docs for the Rust SDK.
Notes to reviewers
┆Attachments: EDU-6184 feat(rust): rust sdk docs