To call a Restate handler and wait for its result:
# import my_service # Import the service module to get to the handler, not the service itself# To call a Service:response = await ctx.service_call(my_service_handler, arg="Hi")# To call a Virtual Object:response = await ctx.object_call(my_object_handler, key="Mary", arg="Hi")# To call a Workflow:# `run` handler — can only be called once per workflow IDresponse = await ctx.workflow_call(run, key="my_workflow_id", arg="Hi")# Other handlers can be called anytime within workflow retentionresponse = await ctx.workflow_call( interact_with_workflow, key="my_workflow_id", arg="Hi")
Use generic calls when you don’t have the service definition or need dynamic service names:
To send a message to another Restate handler without waiting for a response:
# To message a Service:ctx.service_send(my_service_handler, arg="Hi")# To message a Virtual Object:ctx.object_send(my_object_handler, key="Mary", arg="Hi")# To message a Workflow:# `run` handler — can only be called once per workflow IDctx.workflow_send(run, key="my_wf_id", arg="Hi")# Other handlers can be called anytime within workflow retentionctx.workflow_send(interact_with_workflow, key="my_wf_id", arg="Hi")
Restate handles message delivery and retries, so the handler can complete and return without waiting for the message to be processed.Use generic send when you don’t have the service definition:
# To message a Service with a delay:ctx.service_send(my_service_handler, arg="Hi", send_delay=timedelta(hours=5))# To message a Virtual Object with a delay:ctx.object_send( my_object_handler, key="Mary", arg="Hi", send_delay=timedelta(hours=5))# To message a Workflow with a delay:ctx.workflow_send( run, key="my_workflow_id", arg="Hi", send_delay=timedelta(hours=5))
Use generic send with a delay when you don’t have the service definition:
Restate automatically deduplicates calls made during the same handler execution, so there’s no need to provide an idempotency key in that case.
However, if multiple handlers might call the same service independently, you can use an idempotency key to ensure deduplication across those calls.