|
| 1 | +package bpmn_engine |
| 2 | + |
| 3 | +import "github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20" |
| 4 | + |
| 5 | +func (state *BpmnEngineState) handleServiceTask(process *ProcessInfo, instance *processInstanceInfo, element *BPMN20.TaskElement) (bool, *job) { |
| 6 | + job := findOrCreateJob(&state.jobs, element, instance, state.generateKey) |
| 7 | + |
| 8 | + handler := state.findTaskHandler(element) |
| 9 | + if handler != nil { |
| 10 | + job.JobState = Active |
| 11 | + variableHolder := NewVarHolder(&instance.VariableHolder, nil) |
| 12 | + activatedJob := &activatedJob{ |
| 13 | + processInstanceInfo: instance, |
| 14 | + failHandler: func(reason string) { job.JobState = Failed }, |
| 15 | + completeHandler: func() { job.JobState = Completed }, |
| 16 | + key: state.generateKey(), |
| 17 | + processInstanceKey: instance.InstanceKey, |
| 18 | + bpmnProcessId: process.BpmnProcessId, |
| 19 | + processDefinitionVersion: process.Version, |
| 20 | + processDefinitionKey: process.ProcessKey, |
| 21 | + elementId: job.ElementId, |
| 22 | + createdAt: job.CreatedAt, |
| 23 | + variableHolder: variableHolder, |
| 24 | + } |
| 25 | + if err := evaluateLocalVariables(&variableHolder, (*element).GetInputMapping()); err != nil { |
| 26 | + job.JobState = Failed |
| 27 | + instance.State = Failed |
| 28 | + return false, job |
| 29 | + } |
| 30 | + handler(activatedJob) |
| 31 | + if job.JobState == Completed { |
| 32 | + if err := propagateProcessInstanceVariables(&variableHolder, (*element).GetOutputMapping()); err != nil { |
| 33 | + job.JobState = Failed |
| 34 | + instance.State = Failed |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + return job.JobState == Completed, job |
| 40 | +} |
| 41 | + |
| 42 | +func (state *BpmnEngineState) handleUserTask(process *ProcessInfo, instance *processInstanceInfo, element *BPMN20.TaskElement) *job { |
| 43 | + // TODO consider different handlers, since Service Tasks are different in their definition than user tasks |
| 44 | + _, j := state.handleServiceTask(process, instance, element) |
| 45 | + return j |
| 46 | +} |
0 commit comments