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

Activities (async) sample.

// Workflow method impl / workflow function
public String asyncactivities(String name) {
      Promise<String> res1 = Async.function(activities::doSomething, name);
      Promise<String> res2 = Async.function(activities::doSomethingElse, name);

       String r1 = res1.get();
       String r2 = res2.get();
       return r1 + r2;
}

History:

  1. WorkflowExecutionStarted
  2. WorkflowTaskScheduled
  3. WorkflowTaskStarted
  4. WorkflowTaskCompleted
  5. ActivityTaskScheduled
  6. ActivityTaskScheduled

4,5,6 are important here. So your worker has executed the three lines:
Promise res1 = Async.function(activities::doSomething, name);
Promise res2 = Async.function(activities::doSomethingElse, name);
which are two futures, and then
res1.get() is a blocking code which requires us to wait for the results of the res1 promise.
Events 5 and 6 are the events server wrote into history that correspond to the two ScheduleActivity commands that worker has sent to it, one for each of the async activity invocations we requested in code.

  1. ActivityTaskStarted (exec of activity started)
  2. ActivityTaskCompleted (exec of activity completed)
  3. WorkflowTaskScheduled (server asks workers to take a look at progress)
  4. ActivityTaskStarted (exec of activity started)
  5. ActivityTaskCompleted (exec of activity completed)

This is a little bit of an optimization that is done by Temporal, in this example the two async activities completed very fast. The first blocking call to res1.get(); was unblocked but since both activities completed they can be handled within the same workflow task. So the second blocking call res2.get(); was unblocked right away since the res2 activity result was already available in history.

  1. WorkflowTaskStarted
  2. WorkflowTaskCompleted

Worker has executed the return statement

  1. WorkflowExecutionCompleted (server records exec completed)

Hope this helps.

3 Likes