Schedule processes - XLRIT/gears GitHub Wiki

In many situations you would want to run a process periodically, for instance every night, or every month, etc. But you do not want to wake yourself up and start that process yourself. So we want to schedule it to run automatically at a certain moment in time.

This document explains how to do that.

Note: that for now we are going to use an approach which requires you to change files every time after a GEARS: Generate. Later this will be changed to a more permanent and simplified approach.

  1. First create a process as you would normally do with GEARS.

After you have generated it, this should result in a matching .bpmn file in the subfolder path target\ \src\main\resources\processes that looks a bit like this (as an example we use the the process called Increase prices automatically created during GS_08_Update_existing_data) which should be in file target\getting_started\src\main\resources\processes\Increase prices automatically.bpmn:

<definitions targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:flowable="http://flowable.org/bpmn">
  <process id="increase_prices_automatically" name="Increase prices automatically" isExecutable="true" flowable:candidateStarterGroups="product_manager">
    <startEvent id="N1"/>
    <serviceTask id="N2" flowable:delegateExpression="${increase_prices_automatically_Behavior1}"/>
    <endEvent id="N3"/>
    <sequenceFlow id="N1_N2" sourceRef="N1" targetRef="N2"/>
    <sequenceFlow id="N2_N3" sourceRef="N2" targetRef="N3"/>
  </process>
</definitions>

We will not explain it in much detail but basically this file matches the process diagram of the process. As a reference here is a picture of the process diagram of the example process Increase prices automatically:

.

As you can see it is a really simple process that starts <startEvent id="N1"/>, just one Behavior <serviceTask id="N2" .../> and an end <endEvent id="N3"/> and of course a flow from start to Behavior <sequenceFlow id="N1_N2" sourceRef="N1" targetRef="N2"/>, and from Behavior to end <sequenceFlow id="N2_N3" sourceRef="N2" targetRef="N3"/>.

  1. Make the following changes to the .bpmn file (when you are doing this from the Getting started the example file is target\getting_started\src\main\resources\processes\Increase prices automatically.bpmn).
-  <startEvent id="N1"/>
+  <startEvent id="N1">
+      <timerEventDefinition>
+        <timeCycle>0/30 * * ? * * *</timeCycle>
+      </timerEventDefinition>
+    </startEvent>

The text between <timeCycle> and </timeCycle> is called a CRON expression which defines when this process should run. Here is a site that helps you to understand and create CRON schedules: read or create CRON expression. With this siteyou should be able to determine that this CRON schedule will make the process Increase prices automatically run every 30 seconds.

  1. Do a GEARS: Run Application, GEARS: Load data and from the running application open menu Products.
  2. Refresh this Products page at least once every 30 seconds to see if the prices change.

You will notice that prices will increase by 10% every 30 seconds, which means the process does in fact run automatically every 30 seconds.

⚠️ **GitHub.com Fallback** ⚠️