What exactly is a "workflow task" and how often are they scheduled?

You can think of a workflow task as a unit of execution of your workflow code. It’s also the way for server and your workers to communicate together to complete your workflows.

Temporal server manages the overall workflow execution, persistence durable timers etc, but your workflow and activity code is executed by your workers.

A workflow task starts when the server says basically “hey workers I have completed my work so far for this workflow execution, its your turn now to tell me what to do next”. It ends when workers tell server "hey server I’ve executed all the code i can do for now, here are the commands i need you to perform so workflow exec can make progress. (or in case of last workflow task - hey server i have completed execution of all the workflow code here is the result).

Some operations that would cause your worker to block code execution and send commands to server are things like sleep, sync activity/child wf invocation etc.

We can look at a couple of simple code examples and corresponding workflow history maybe that would help.
Samples are in java but would apply to any sdk:

  1. Simple

// Workflow method impl / workflow function
public String simple(String name) {
   return "Hello: "  + name;
}

Corresponding wf history:

  1. WorkflowExecutionStarted (your client requested execution to be created and started)
  2. WorkflowTaskScheduled (server scheduled a task and placed it on the tq that client requested)
  3. WorkflowTaskStarted (your worker picked up the task)

at this point your worker is going to start executing workflow code, it will execute the return command. It then has to report back to the server that the execution has completed.

  1. WorkflowTaskCompleted (worker has completed wf execution and sent a CompleteWorkflowExecution command back to server, note this command is not recorded in history, but some others are which we will see in next sample).
  2. WorkflowExecutionCompleted (server has completed the execution, if there is a result the server reports the result to client if the client is waiting for it)

(will put next sample in another post)

4 Likes