We use Spring Batch to create one-off and scheduled jobs.
For a one-off job:
- Create a new package under
uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jobs.oneoff
- For an example job, see #1286
For a scheduled job:
- Create a new package under
uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jobs.scheduled
- For an example job, see the NDMIS report job
For both:
- Provide an
ApplicationRunner
@Bean
to make the job callable from command line, see #1348 or this example - Create a
CronJob
or aJob
inhelm_deploy
that will let it be executed on the environments, see this example
For both kind of jobs, running locally:
SPRING_PROFILES_ACTIVE=local ./gradlew bootRun --args='--jobName=changelogMigrationJob'
To pass in arguments, use key=value
pairs:
SPRING_PROFILES_ACTIVE=local ./gradlew bootRun --args='--jobName=transferReferralsJob fromContract=FROM toContract=TO'
To run on environments, assuming a CronJob
, please see triggering scheduled jobs from the runbook.