A quickstart project shows use of timer based activities within the process to allow a flexible delays before continuing process execution. There are two types of timers used in this quick start
- intermediate timer event - used as part of the regular process flow to introduce delays
- boundary timer event - used as an option to move process flow through alternative path after expiration time
This example shows
-
working with timers (both intermediate and boundary)
-
optionally use Job Service that allows to externalize time tracking to separate service and by that offload the runtime service
-
Intermediate timer event (timers.bpmn)
- Intermediate timer Diagram Properties (top)
- Intermediate timer Diagram Properties (bottom)
- Intermediate timer Before Timer
- Intermediate timer Timer
- Intermediate timer After Timer
- Boundary timer event (timer-on-task.bpmn)
- Boundary timer Diagram Properties (top)
- Boundary timer Diagram Properties (bottom)
- Boundary timer Before Timer
- Boundary timer User Task (top)
- Boundary timer User Task (bottom)
- Boundary timer Timer
- Boundary timer After Timer
- Cycle timer event (timerCycle.bpmn)
- Cycle timer Diagram Properties (top)
- Cycle timer Diagram Properties (bottom)
- Cycle timer Before Timer
- Cycle timer Timer
- Cycle timer AfterTimer
Timer expression is expected to be given in ISO-8601 format e.g. PT30S - wait 30 seconds before expiring. This needs to be given when starting process instance as delay attribute of type string.
You will need:
- Java 11+ installed
- Environment variable JAVA_HOME set accordingly
- Maven 3.6.2+ installed
When using native image compilation, you will also need:
- GraalVM 19.3+ installed
- Environment variable GRAALVM_HOME set accordingly
- GraalVM native image needs as well native-image extension: https://www.graalvm.org/docs/reference-manual/native-image/
- Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too, please refer to GraalVM installation documentation for more details.
mvn clean package quarkus:dev
NOTE: With dev mode of Quarkus you can take advantage of hot reload for business assets like processes, rules, decision tables and java code. No need to redeploy or restart your running application.
Note that this requires GRAALVM_HOME to point to a valid GraalVM installation
mvn clean package -Pnative
To run the generated native executable, generated in target/
, execute
./target/kogito-timer-quarkus-{version}-runner
To make use of this application it is as simple as putting a sending request to http://localhost:8080/timers
with following content
{
"delay" : "PT30S"
}
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"delay" : "PT30S"}' http://localhost:8080/timers
curl -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/timers
curl -X DELETE 'http://localhost:8080/timers/{uuid}'
where {uuid}
is the id of the given timer instance
To make use of this application it is as simple as putting a sending request to http://localhost:8080/timerscycle
with following content
{
"delay" : "R2/PT1S"
}
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"delay" : "R2/PT1S"}' http://localhost:8080/timerscycle
curl -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/timerscycle
curl -X DELETE 'http://localhost:8080/timerscycle/{uuid}'
where {uuid}
is the id of the given timer cycle instance
To make use of this application it is as simple as putting a sending request to http://localhost:8080/timersOnTask
with following content
{
"delay" : "PT30S"
}
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"delay" : "PT30S"}' http://localhost:8080/timersOnTask
curl -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/timersOnTask
curl -X DELETE 'http://localhost:8080/timersOnTask/{uuid}'
where {uuid}
is the id of the given timer instance
After executing the above commands you should see a log similar to
- Quarkus Log
Before timer... waiting for PT30S
After Timer
Before timer, waiting for task to be complete or expires in PT30S
After Timer
Before timer... waiting for R2/PT1S
After Timer
After Timer
There is additional configuration needed in
- application.properties
- pom.xml
To allow to use Job Service as timer service there is a need to specify additional properties
kogito.jobs-service.url=http://localhost:8085
kogito.service.url=http://localhost:8080
First one is used to direct the Kogito runtime to let it know where is the Kogito Job Service - it needs to match the location of the Kogito Job Service when starting it - see below. Second one is used by Kogito Job Service to callback when the timer expires and needs to be pointing to the service host and port
To be able to use Kogito Job Service as timer service additional dependency needs to be added
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>jobs-management-quarkus-addon</artifactId>
</dependency>
You need to download the job service and start it locally
You can download it from [Select Latest Version] https://repo.maven.apache.org/maven2/org/kie/kogito/jobs-service/
java -Dquarkus.http.port=8085 -jar target/jobs-service-{version}-runner.jar
- After Starting Kogito Web Service you should see a similar Log as follows
Note that in the above log infinispan has started on port 11222
In case you'd like to run the job service with enabled persistence then start Infinispan server before and then run the job service with following command
Download Infinispan Server from https://infinispan.org/download/
Start Infinispan Server [Infinispan Directory]/bin/sh server.sh
java -Dquarkus.http.port=8085 -Dkogito.jobs-service.persistence=infinispan -jar target/jobs-service-{version}-runner.jar
in both cases replace {version}
with actual Kogito version to be used (Job Service is available from 0.6.0)
- After Starting Infinispan you should see a similar Log as follows
After that you can redo the timer queries described above