|
| 1 | +[[dev-guide-scheduled-jobs]] |
| 2 | += Scheduled Jobs |
| 3 | +{product-author} |
| 4 | +{product-version} |
| 5 | +:data-uri: |
| 6 | +:icons: |
| 7 | +:experimental: |
| 8 | +:toc: macro |
| 9 | +:toc-title: |
| 10 | +:prewrap!: |
| 11 | + |
| 12 | +toc::[] |
| 13 | + |
| 14 | +== Overview |
| 15 | + |
| 16 | +A _scheduled job_ builds on a regular |
| 17 | +xref:../dev_guide/jobs.adoc#dev-guide-jobs[job] by allowing you to specifically |
| 18 | +schedule how the job should be run. Scheduled jobs are part of the |
| 19 | +link:http://kubernetes.io/docs/user-guide/scheduled-jobs[Kubernetes] API, which |
| 20 | +can be managed with `oc` commands like other |
| 21 | +xref:../cli_reference/basic_cli_operations.adoc#object-types[object types]. |
| 22 | + |
| 23 | +ifdef::openshift-enterprise[] |
| 24 | +[NOTE] |
| 25 | +==== |
| 26 | +As of {product-title} 3.3.1, Scheduled Jobs is a feature in Technology Preview. |
| 27 | +==== |
| 28 | +endif::[] |
| 29 | + |
| 30 | +[[creating-a-scheduledjob]] |
| 31 | +== Creating a Scheduled Job |
| 32 | + |
| 33 | +A scheduled job configuration consists of the following key parts: |
| 34 | + |
| 35 | +* A schedule specified in link:https://en.wikipedia.org/wiki/Cron[cron format]. |
| 36 | +* A job template used when creating the next job. |
| 37 | +* An optional deadline (in seconds) for starting the job if it misses its |
| 38 | +scheduled time for any reason. Missed jobs executions will be counted as failed |
| 39 | +ones. If not specified, there is no deadline. |
| 40 | +* `*ConcurrencyPolicy*`: An optional concurrency policy, specifying how to treat |
| 41 | +concurrent jobs within a scheduled job. Only one of the following concurrent |
| 42 | +policies may be specified. If not specified, this defaults to allowing |
| 43 | +concurrent executions. |
| 44 | +** `Allow` allows Scheduled Jobs to run concurrently. |
| 45 | +** `Forbid` forbids concurrent runs, skipping the next run if the previous has not |
| 46 | +finished yet. |
| 47 | +** `Replace` cancels the currently running job and replaces |
| 48 | +it with a new one. |
| 49 | +* An optional flag allowing the suspension of a scheduled job. If set to `true`, |
| 50 | +all subsequent executions will be suspended. |
| 51 | + |
| 52 | +The following is an example of a `*ScheduledJob*` resource: |
| 53 | + |
| 54 | +==== |
| 55 | +[source,yaml] |
| 56 | +---- |
| 57 | +apiVersion: batch/v2alpha1 |
| 58 | +kind: ScheduledJob |
| 59 | +metadata: |
| 60 | + name: pi |
| 61 | +spec: |
| 62 | + schedule: */1 * * * ? <1> |
| 63 | + jobTemplate: <2> |
| 64 | + spec: |
| 65 | + template: |
| 66 | + spec: |
| 67 | + containers: |
| 68 | + - name: pi |
| 69 | + image: perl |
| 70 | + command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] |
| 71 | + restartPolicy: Never |
| 72 | +---- |
| 73 | +
|
| 74 | +1. Schedule for the job. In this example, a job will run every minute. |
| 75 | +2. Job template. This is similar to the xref:../dev_guide/jobs.adoc#creating-a-job[job example]. |
| 76 | +==== |
| 77 | + |
| 78 | +ifdef::openshift-enterprise[] |
| 79 | +[[scheduledjob-known-issues]] |
| 80 | +== Known Issues |
| 81 | + |
| 82 | +[[scheduledjob-known-issues-unable-to-edit]] |
| 83 | +=== Unable to Edit a Scheduled Job |
| 84 | + |
| 85 | +There is a link:https://bugzilla.redhat.com/show_bug.cgi?id=1378368[known issue] |
| 86 | +when invoking `oc edit scheduledjob` due to an error that was already fixed in |
| 87 | +the latest version. However, due to significant code changes, this was not |
| 88 | +backported. |
| 89 | + |
| 90 | +One possible solution is to use `oc patch` command instead of `oc edit`. |
| 91 | + |
| 92 | +[[scheduledjob-known-issues-change-concurrency]] |
| 93 | +=== Unable to Change Concurrency Policy |
| 94 | + |
| 95 | +There is a link:https://bugzilla.redhat.com/show_bug.cgi?id=1386463[known issue] |
| 96 | +when changing concurrency policy where no new jobs are created after that |
| 97 | +operation is run. The issue is still under investigation in the latest version. |
| 98 | +endif::[] |
0 commit comments