Quick question about External Task and their usage

Hello everyone, im a bit confused about external tasks.
From what ive learned external tasks are like service tasks but they are called from an external api.

Lets say that i have a simple workflow like this:

Both are external tasks so when the process start then it will stop on the first task and wait for an /external-task/{id}/complete.

Now what I dont really understand.
How can the outside spring application know when to execute the post above and call this specific topic since it doesnt know the status of the process?

So basically from what im understanding the external tasks are used when the status of the process is not important, right?

Thank you and sorry for the confusion.

Hi @francesco_giberti,

Camunda External Task Client allows to set up remote Service Tasks for your workflow.

The process engine supports two ways of executing service tasks:

  1. Internal Service tasks: Synchronous invocation of code deployed along with a process application.

  2. External tasks: Providing a unit of work in a list that can be polled by workers.

    • Process engine publishes a unit of work to a worker to fetch and complete, and this process is called as external task pattern.

    • Pull approach, where external worker threads query Camunda for “external service tasks”.

    • Pull a service task into an external worker thread and inform process engine of completion.


image



Read about the External Task Pattern and usage of ExternalTaskService.


List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(10, "externalWorkerId")
  .topic("AddressValidation", 60L * 1000L)
  .execute();

for (LockedExternalTask task : tasks) {
  try {
    String topic = task.getTopicName();

    // work on task for that topic
    ...

    // if the work is successful, mark the task as completed
    if(success) {
      externalTaskService.complete(task.getId(), variables);
    }
    else {
      // if the work was not successful, mark it as failed
      externalTaskService.handleFailure(
        task.getId(),
        "externalWorkerId",
        "Address could not be validated: Address database not reachable",
        1, 10L * 60L * 1000L);
    }
  }
  catch(Exception e) {
    //... handle exception
  }
}

Refer the equivalent rest api for externalTaskService.fetchAndLock() and the rest api for externalTaskService.complete().


Reference blogs for External Tasks are:



4 Likes

Amazing answer! thank you