Deleting tasks using TaskService

749 views
Skip to first unread message

Cristian Cerb

unread,
Mar 11, 2015, 7:06:05 PM3/11/15
to camunda-...@googlegroups.com
Guys,

When a user task completes using TaskService.completeTask method, as I can see in class TaskEntity:

  public void complete() {
    // if the task is associated with a case
    // execution then call complete on the
    // associated case execution. The case
    // execution handles the completion of
    // the task.
    if (caseExecutionId != null) {
      getCaseExecution().manualComplete();
      return;
    }

    // in the other case:

    // ensure the the Task is not suspended
    ensureTaskActive();

    // trigger TaskListener.complete event
    fireEvent(TaskListener.EVENTNAME_COMPLETE);

    // delete the task
    Context
      .getCommandContext()
      .getTaskManager()
      .deleteTask(this, TaskEntity.DELETE_REASON_COMPLETED, false);

    // if the task is associated with a
    // execution (and not a case execution)
    // then call signal an the associated
    // execution.
    if (executionId!=null) {
      ExecutionEntity execution = getExecution();
      execution.removeTask(this);
      execution.signal(null, null);
    }
  }

But when delete TaskService.deleteTask is called, there is not signaling, as I can see in same class TaskEntity:

  public void delete(String deleteReason, boolean cascade) {
    this.deleteReason = deleteReason;
    fireEvent(TaskListener.EVENTNAME_DELETE);

    Context
      .getCommandContext()
      .getTaskManager()
      .deleteTask(this, deleteReason, cascade);

    if (executionId != null) {
      ExecutionEntity execution = getExecution();
      execution.removeTask(this);
    }
  }

My question is: what happens to process instance when a user task is canceled from within using TaskService.deleteTask?

Cristian

Roman Smirnov

unread,
Mar 12, 2015, 4:59:31 AM3/12/15
to camunda-...@googlegroups.com
Hi Cristian,

See [1]. In such a case an exception will be thrown, so that you are not able to delete a task which is associated with a process instance.

Cheers,
Roman

Cristian Cerb

unread,
Mar 12, 2015, 11:20:08 AM3/12/15
to camunda-...@googlegroups.com
Thank you, Roman. Then what is the meaning of Daniel Meyer's comment on post "Completed vs. Deleted Tasks / Instances". He wrote something like: 

"Hi Carsten,

with 7.1.0 we also introduced the new method HistoricActivityInstance.isCanceled() This allows you to check whether an activity instance was completed or cancelled. Beware though: the cancelled state can either result from a user cancelling the activity manually or from an interrupting BPMN activity (such as a boundary event) beeing fired.

The HistoricProcessInstance also provides a getDeleteReason() field. If you call RuntimeService.deleteProcessInstance('...') you can provide it.

Cheers,
Daniel"

Cristian

Roman Smirnov

unread,
Mar 12, 2015, 12:03:53 PM3/12/15
to camunda-...@googlegroups.com
I am not sure, but maybe he means with his statement "RuntimeService#deleteProcessInstance()". In that case active activity instances will be marked as cancelled too.

Cheers,
Roman

Daniel Meyer

unread,
Mar 12, 2015, 12:05:08 PM3/12/15
to camunda-...@googlegroups.com
Yes, that was probably what he meant ... ;)

daniel

Cristian Cerb

unread,
Mar 12, 2015, 12:28:55 PM3/12/15
to camunda-...@googlegroups.com
Ok, Daniel :) But what is the meaning of "user cancelling the activity manually" in your other post? Could you elaborate a bit, please?

Roman Smirnov

unread,
Mar 12, 2015, 5:06:11 PM3/12/15
to camunda-...@googlegroups.com
Just for clarification: It is not possible to cancel a specific activity instance by using the public API. As I already wrote when deleting a process instance by using "RuntimeService#deleteProcessInstance()" current active activity instances will be marked as cancelled in the history. The other cases in which an active activity instance will be marked as cancelled are when for example an attached interrupting boundary event will be triggered and so on.

Cheers,
Roman

Roman Smirnov

unread,
Mar 13, 2015, 3:37:36 AM3/13/15
to camunda-...@googlegroups.com
Sorry, I forgot one thing. With 7.3 it will be possible to modify a process instance (see [1], [2]). This feature also offers you the possibility to cancel an activity instance.

Cheers,
Roman

Cristian Cerb

unread,
Mar 13, 2015, 3:28:44 PM3/13/15
to camunda-...@googlegroups.com
Thank you, Roman. Does that mean deletion will signal process execution as well?
Reply all
Reply to author
Forward
0 new messages