Quartz scheduler implementation using JobStore with PostgreSQL.
First of all, you may need to be running a PostgreSQL instance, that is out of the scope of this article. As an alternative, you can run PostgreSQL in a container using Docker.
After PostgreSQL is running and accessible, set connections params in application.yml.
spring:
datasource:
driver: org.postgresql.Driver
url: jdbc:postgresql://<ip-address>:<port>/<db-name>
username: <db-user>
password: <db-pass>
Run the app:
$ ./mvnw spring-boot:run
$ curl -X POST \
'http://localhost:8080/job' \
-H 'content-type: application/json' \
-d '{
"jobName": "JobTest",
"jobGroup": "JobGroup",
"cronExpression": "0/2 * * ? * *",
"payload": "Testing scheduler job"
}'
This job will be fired every 2 seconds.
Cron expression could be done using Cron Expression Generator & Explainer - Quartz.
$ curl -X DELETE \
'http://localhost:8080/job?jobName=JobTest&jobGroup=JobGroup'