Skip to main content

Trigger scheduled jobs

Desired behaviour

One of the scheduled jobs needs to be re-run immediately.

Actions

  1. Stop the job if it is running:

    Check the active jobs:

    kubectl get jobs --namespace=hmpps-interventions-{namespace}
    

    If it is running, delete it with kubectl delete jobs/{name}.

    Warning Jobs are not written with concurrency in mind. It is unsafe to run them concurrently.
  2. Find the job you need to execute:

    $ kubectl get cronjobs --namespace=hmpps-interventions-{namespace}
    

    For example, on pre-prod:

    $ kubectl get cronjobs --namespace=hmpps-interventions-preprod
    NAME                                SCHEDULE     SUSPEND   ACTIVE   LAST SCHEDULE   AGE
    data-extractor-analytics            0 1 * * *    False     0        11h             277d
    generate-ndmis-performance-report   30 0 * * *   False     0        12h             277d
    
  3. Trigger an immediate execution of the job:

    $ kubectl create job --namespace=hmpps-interventions-{namespace} \
      --from=cronjob.batch/{name} "{name}-$(date +'%s')"
    

    The new job will be timestamped (date +'%s') so it is trackable.

    For example, triggering a data-extractor-analytics job on pre-prod:

    $ kubectl create job --namespace=hmpps-interventions-preprod \
      --from=cronjob.batch/data-extractor-analytics "data-extractor-analytics-$(date +'%s')"
    
This page was last reviewed on 5 March 2025. It needs to be reviewed again on 5 March 2026 by the page owner #interventions-dev .
This page was set to be reviewed before 5 March 2026 by the page owner #interventions-dev. This might mean the content is out of date.