AnsweredAssumed Answered

execution.take() creates a new activity instance

Question asked by eransinger on Jun 4, 2015
Latest reply on Jun 11, 2015 by jbarrez
Hello,
I have a flow with an external agent doing a job triggered by an activiti service task.
I want to be able to model the signals sent by this agent as exception or successe in the activiti.

i do not want to wrap my service task with boundery events, or proccess or sequence flows.

I tried implementing my own TaskActivityBehavior in a way that when the signal received is a failed one- i am calling execution.take()

Problem is each time it creates a new activity instance so retries are not decreasing and there is a loop.
Do you have any idea of how can i go back from the signal to the execution without creating a new activity?

Thanks in advance
———————————–

public void execute(ActivityExecution execution) throws Exception {
        try {
            if(ActivityLocalContext.getProperty('jobStatus').equals('fail')){
                throw new FailedException("job failed");
            }
            String jobId = submitAction(migrationRule, titleId, execution.getId());
            ActivityLocalContext.setProperty(execution, "jobStatus", "Running");
            ActivityLocalContext.setProperty(execution, "jobId", jobId);
        } catch (Exception e) {
            if(failedAndNoMoreRetries()){
                 ActivityLocalContext.setProperty(execution, "jobStatus", "New");
            }
            logger.error("ApplyMigrationPolicy->notifiy() failed: " + e.getMessage(), e);
            throw new FailedException("ApplyMigrationPolicy->notifiy() failed: " + e.getMessage());
        }
    }

    public void signal(ActivityExecution execution, String signalName, Object data) throws Exception {
        PvmTransition inTransition = execution.getActivity().getIncomingTransitions().get(0);
        if(signaledException()) {
            ActivityLocalContext.setProperty(execution, "jobStatus", "Failed");
                execution.take(inTransition);
        }else {
            ActivityLocalContext.setProperty(execution, "jobStatus", "complete");
            this.leave(execution);
        }
    }

Outcomes