This is a demo project to showcase dynamic job scheduling using JobRunR.
It schedules jobs using a REST API and cron expressions.
Jobs just print messages to the console.
Use REST calls to create, update, delete jobs.
Jobs are persisted to Postgres DB. After a restart, the scheduler will continue existing job's execution.
If you plan to use code from this project in production, be exremely careful as the failure handling and transaction managment needs improvement.
- Java 21
- Docker v20.03.0+
- Docker Compose v2.0.0+
- Run
docker compose up
to start Postgres (ordocker-compose up
if you have older version) - Run
mvn spring-boot:run
to start the application
docker compose down
to stop Postgressudo rm -rf volumes/postgres
to delete the Postgres data directory
Get all jobs
curl -X 'GET' 'http://localhost:8080/jobs'
Create a job
curl -X 'POST' \
'http://localhost:8080/jobs/create' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"name": "job1",
"message": "job1 message",
"cronExpression": "* * * * *",
"retries": 1
}'
Update a job
curl -X 'PUT' \
'http://localhost:8080/jobs/update-by-name/job1' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"name": "job1-new",
"message": "updated message",
"cronExpression": "* * * * *",
"retries": 2
}'
Delete a job
curl -X 'DELETE' 'http://localhost:8080/jobs/delete-by-name/job1-new'
- See logs to inspect job execution:
less logs/dynamic-job-scheduling.log