cancel
Showing results for 
Search instead for 
Did you mean: 

timerEventDefinition and process runs upon startup

sanjiv
Champ in-the-making
Champ in-the-making
I'm trying to setup a simple workflow that causes one of the API's on a bean be invoked at 3:30, 4:30 and 5:30pm.

I'm using the code below but what I'm seeign happen is that when the code runtimeService.startProcessInstanceByKey() is invoked, the process runs immediately as I see that mySerivce.process() is being invoked. I do not want it to be invoked immediately but rather only on the scheduled timeCycle.

Any suggestions?

Thanks,
Sanjiv


Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("bpmn/my-timer.bpmn20.xml")
                .deploy();

        Map<String, Object> variableMap = new HashMap<String, Object>();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcessTimer", variableMap);




<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             targetNamespace="http://www.bpmnwithactiviti.org"
             xmlns:activiti="http://activiti.org/bpmn">

    <process id="myProcessTimer" name="Scheduled Process">
        <startEvent id="timerstartevent1">
            <timerEventDefinition>
                <!–run at 3:30, 4:30 and 5:30 every weekday–>
                <timeCycle>0 30 15,16,17 ? * MON-FRI</timeCycle>
            </timerEventDefinition>
        </startEvent>

        <sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="processVariationMargin"></sequenceFlow>

        <serviceTask id="processVariationMargin"
                     activiti:expression="#{mySerivce.process()}"/>

    </process>
</definitions>
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
If you have a timer-start event, there is no need to call "startProcessBy…". If a process with a timer-start-event is deployed into the engine, this timer-job is added and the process will be started on the scheduled time(s).

This is mentioned in the user guide, maybe good to read the relevant sections first (http://activiti.org/userguide/index.html#bpmnTimerStartEvent😞
Note: start timer event is scheduled as soon as process is deployed. There is no need to call startProcessInstanceByXXX, although calling start process methods is not restricted and will cause one more starting of the process at the time of startProcessInstanceByXXX Invocation.

sanjiv
Champ in-the-making
Champ in-the-making
That works, thank you. I was hoping to use a process variable like <timeCycle>${duration}</timeCycle> but the process variables are passed when calling startProcessInstanceByXXX. Is there any way to use process variables with a timer start event?

Thanks,
Sanjiv

jbarrez
Star Contributor
Star Contributor
No. Also, how would you know what to pass when the timer fires?
If the variables are predefined, you can attach an execution listener that adds these variables after the start event.

sanjiv
Champ in-the-making
Champ in-the-making
Yes, the variables are predefined. I'll look into it, thanks.