You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dev_guide/cron_jobs.adoc
+23-6Lines changed: 23 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -45,8 +45,10 @@ endif::[]
45
45
[WARNING]
46
46
====
47
47
A cron job creates a job object approximately once per execution time of its
48
-
schedule, but there are circumstances in which it will fail to create a job or
49
-
two jobs might be created. As a result, jobs should be idempotent.
48
+
schedule, but there are circumstances in which it fails to create a job or
49
+
two jobs might be created. Therefore, jobs should be idempotent and you
50
+
should monitor and xref:cleaning-up-after-a-cron-job[clean cron jobs]
51
+
frequently.
50
52
====
51
53
52
54
[[creating-a-cronjob]]
@@ -127,14 +129,29 @@ Doing this prevents them from generating unnecessary artifacts.
127
129
[[cleaning-up-after-a-cron-job]]
128
130
== Cleaning Up After a Cron Job
129
131
130
-
Cron jobs can leave behind artifact resources such as jobs or pods. Check if any remain:
132
+
Cron jobs can leave behind artifact resources such as jobs or pods. Configuring history limits is important, so that old jobs and their pods are properly cleaned. There are
133
+
two optional fields within cron job's spec responsible for that:
131
134
135
+
[source,yaml]
132
136
----
133
-
$ oc get jobs
134
-
$ oc get pods
137
+
apiVersion: batch/v2alpha1
138
+
kind: CronJob
139
+
metadata:
140
+
name: pi
141
+
spec:
142
+
successfulJobsHistoryLimit: 3 <1>
143
+
failedJobsHistoryLimit: 1 <2>
144
+
schedule: "*/1 * * * *"
145
+
jobTemplate:
146
+
spec:
147
+
...
135
148
----
136
149
137
-
All artifacts left over from a job execution use the job name as their prefix. For example, given the cron job example:
150
+
<1> The number of successful finished jobs to retain.
151
+
<2> The number of failed finished jobs to retain.
152
+
153
+
At any point in time, you can manually verify all artifacts left over from a job execution by using
154
+
the job name as their prefix. For example, given the cron job example:
0 commit comments