Hello. I’m new to temporal and I writing my first application using .NET SDK
My dotnet service starts hosted temporal worker and also starts all workflows.
builder.Services.AddHostedTemporalWorker("my-queue")
.AddScopedActivities<SetStateWorkflow.Activities>()
.AddWorkflow<SetStateWorkflow>()
I need to synchronize execute of certain activity for each object. The object has id, let’s name it ObjectId. I’m aware that Temporal itself will not keep order of execution basing on start time. My solution is:
I have a queue for each ObjectId
- At workflow run I add workflow handle to a queue
- At activity execution I check if the current workflow is at the first element of queue, if not it waits for all preceding workflows
In theory it is a good solution, but yet I’m facing some serious issues
When service starts I need a list of running workflows along with associated ObjectId before worker starts and run activities. To get ObjectId of a workflow I use query which gives me a timeout.
I realized that probably I need worker running to execute a query so pulling workflows is not blocking application running (with app.Run()
).
Now query works, but other issue came up. Now activities are executed which needs that queue, which isn’t filled up yet. I could add to activity an await for that task to be completed. But this is only startup scenario and I would check for every activity for service lifetime. I would rather prefer put worker on hold and do not start activities until the task is finished and I call to resume.
My question is: can I not start a worker and in meantime execute queries? Or maybe deffer activities execution? Or maybe there is other, better approach to this?