Pergunta

When I set a process variable through org.camunda.bpm.engine.cdi.BusinessProcess.setVariable() it seems the value is not automatically flushed.

Is there a way to flush the variables without completing the current user task? I thought BusinessProcess.signalExecution() would be the solution but it seems to complete the current task just as BusinessProcess.completeTask() does.

What exactly is the difference between signalExecution and completeTask?

Foi útil?

Solução

Variables are cached in the Request or Conversation until the unit of work is ended, for example by calling completeTask(). There is currently no out-of-the-box solution for manually flushing the cached variables. You could work around this by writing a Cdi Bean which injects the ContextAssociationManager and performs the flush:

@Inject
private ContextAssociationManager contextAssociationManager;

@Inject 
private TaskService taskService;

public void flushCachedVariables() {
  String taskId = contextAssociationManager.getTask().getId();
  taskService.setVariables(taskId, contextAssociationManager.getCachedVariables());
}

The difference between signalExecution and completeTask is as follows:

  • completeTask: will complete the currently associated task using the TaskService
  • signalExecution: is more abstract: it sends a signal to the currently associated execution to continue execution. In this case the effect is the same: the task is completed and execution continue. But signalExecution will also work in situations where there is no Human Task involved (ie. a ReceiveTask).
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top