Hi there.
There’s a documentation on Temporal Python SDK synchronous vs. asynchronous Activity implementations
However, I couldn’t find a full working example of the worker to run synchronous activities.
Basically, what I want to achieve is to:
- run multiple workers running synchronous activities in a single-threaded single-process fashion
- deploy them to k8s
- scale them via HPA
- when this setup (baseline) is stable, consider improving performance either via async or by leveraging concurrency (thread/process pool).
Using money transfer as an example, this is a code I’m talking about:
async def main() -> None:
client: Client = await Client.connect("localhost:7233", namespace="default")
# Run the worker
activities = BankingActivities()
worker: Worker = Worker(
client,
task_queue=MONEY_TRANSFER_TASK_QUEUE_NAME,
workflows=[MoneyTransfer],
activities=[activities.withdraw, activities.deposit, activities.refund],
)
await worker.run()
if __name__ == "__main__":
asyncio.run(main())
- I assume I’d need to add
activity_executor
(Thread Pool or Process Pool) to the worker config. - Should it use
asyncio
library,async
functions andawait
at all?
Thanks in advance