Skip to content

SkourtsidisGiorgos/Demo-JobRunR-Dynamic-Job-Scheduling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JobRunR Dynamic job scheduler

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.

Pre-requisites

  • Java 21
  • Docker v20.03.0+
  • Docker Compose v2.0.0+

Run

  • Run docker compose up to start Postgres (or docker-compose up if you have older version)
  • Run mvn spring-boot:run to start the application

Clean-up

  • docker compose down to stop Postgres
  • sudo rm -rf volumes/postgres to delete the Postgres data directory

Usage

  • Using Swagger UI: http://localhost:8080/swagger-ui/index.html Screenshot from 2024-01-08 15-18-46

  • Using curl:

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

Screenshot from 2024-01-08 15-25-18

  • Visit Web UI: http://localhost:8000/dashboard/recurring-jobs Screenshot from 2024-01-08 15-23-29

References

About

Example project. JobRunR dynamic job scheduling using REST API

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages