[Feature Request] Rust SDK - Queries
Is your feature request related to a problem? Please describe.
I'm trying to use this library in Rust and implement Workflows that have some queryable state. However, I can't find a way to make or handle queries, it seems there's something lacking here. Either that or I'm missing something. All I could find was respond_legacy_query, what's that by the way?
Describe the solution you'd like
An API akin to what's there in Go code samples: https://legacy-documentation-sdks.temporal.io/go/how-to-use-queries-in-go https://legacy-documentation-sdks.temporal.io/go/how-to-handle-a-query-in-a-workflow-in-go
@Elvecent Indeed, they're not implemented in the Rust SDK itself.
The Rust SDK in this repo exists only for internal testing purposes at this point and comes with no API stability guarantees. As such I probably won't be able to prioritize adding arbitrary query support to it unless I happen to have a reason to need it for testing.
Once we've prioritized releasing a production ready Rust SDK, I plan on changing the API quite a bit, to be trait based, and the main reason I haven't added any real query support yet is because it looks quite funky without a very different API.
If you wanted to contribute something which looks like:
impl WfContext {
fn register_query(&self, query_name: impl Into<String>, query_fn: impl Fn() -> Payload) {}
}
I'd be open to that as an intermediate solution
Thanks for the explanation. It's presently not a pressing need for me, but if that changes, I'll look into it.
@Sushisource is an official Temporal Rust SDK library on a roadmap for future ?
@remeq See the blurb at the end of the README here. We do not have official plans to productionize yet.
I was going to implement them myself and have a couple of questions regarding that.
- How much and what exactly is left for them to be implemented? I've seen there were some developments in https://github.com/temporalio/sdk-core/pull/135 but it appears that they're still unimplemented in WorkflowFuture::handle_job endpoint.
- I tried doing it with the analogy with signal jobs, but couldn't find where these signals (besides tests) are consumed. It'll be really helpful knowing that.
Ok, the second part was clarified. The first question is still open.
It would seem that at least we would need to add
- A hashmap like
sig_chanstoWorkflowFuturethat would map query names toimpl Fn() -> Payloadcallbacks - A
QueryWorkflowcommand handler inWorkflowFuture::handle_jobthat looks up in said hashmap and executes the callback - A
SubscribeQueryvariant toRustWfCmdenum together with a corresponding match branch - A
register_workflowmethod forWfContextthat populates the hashmap by callingRustWfCmd::SubscribeQuery
If I'm not missing something non-trivial, this should be rather straightforward.
@Elvecent Yep that's pretty much all right (though I think in 4 you meant to name it register_query_handler or similar).
I think a hit the gotcha. I don't see a way to complete the query request after the result is computed in WorkflowFuture::handle_job
@Elvecent I see, yes you'll need to plumb some way to include query responses in the outgoing commands for completion.
Probably the easiest thing to do would be to simply store a new list of query responses on the WorkflowFuture itself, and then drain those and include them in the completion inside of send_completion
@Sushisource Could you please clarify what do you refer to as send_completion? I'm not sure where to look for it
@Sushisource Could you please clarify what do you refer to as
send_completion? I'm not sure where to look for it
It's a method defined on WorkflowFuture
@Elvecent did you ever manage to finish your implementation or have a work in progress somewhere that you could share?
@c-thiel here's what I have: https://github.com/Elvecent/sdk-core/tree/queries I ended up not needing it, though, so it's hardly tested