0

I've read these docs over multiple times but still don't think I understand what startingDeadlineSeconds does.

I'm trying to figure out if it's possible to avoid rescheduling a job if a current one is running (with CronJob) and instead just let the next scheduled job pick up where it left off.

I have some extremely erratic job completion times (a separate problem I need to solve). It may take 1 hour or up to 24. So sometimes, if a Job takes a whole day to complete, but I've scheduled it to run every 12 hours, I get a queue of another job that immediately starts when the last one is complete.

I'd really just like it to never queue up a job and only create new jobs on the next scheduled time.

Here's a sample of the config

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: my-job
spec:
  schedule: "0 */2 * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  jobTemplate:
    spec:
      backoffLimit: 1
      template:
        spec:
          containers:
          - name: my-job
            image: my-image
            command: ["do_something"]
          restartPolicy: OnFailure

Note that do_somethign could take 1 hour, or it could take 4 hours. What I'd like, is when it takes 4 hours, to not have queued up the 2nd job that would have normally run if it had taken less.

Is this possible with Kubernetes CronJob?

brad
  • 492
  • 1
  • 10
  • 22
  • The docs make it sound like `concurrencyPolicy` controls this behavior. But I think you should post the `CronJob` so we can see all the settings being used. – Andy Shinn Sep 10 '19 at 03:12
  • 1
    `concurrencyPolicy` only affects whether 2 jobs can run at the same time. Ya good call, I'll post the cronjob sample – brad Sep 13 '19 at 13:54
  • If I understand correctly, the `concurrencyPolicy` will prevent the job from running in parallel _but_ queues it up to run immediately after the current one is finished, which is what you are trying to prevent (you would rather it skipped)? – Andy Shinn Sep 13 '19 at 23:01
  • correct, it queues up a 2nd job, and I'd rather have it skipped – brad Sep 15 '19 at 17:44
  • I have made some research and your `CronJob` seems to be correct. Looking at [this question](https://stackoverflow.com/questions/52691631/kubernetes-cronjob-skip-job-if-previous-is-still-running-and-wait-for-the-next) also proves that it should be working as you want it to. Try without `successfulJobsHistoryLimit` and `backoffLimit`. Make it look like more the example below: – Wytrzymały Wiktor Sep 20 '19 at 12:13
  • `apiVersion: batch/v1beta1 kind: CronJob metadata: name: your-cron spec: schedule: "*/40 8-18 * * 1-6" concurrencyPolicy: Forbid jobTemplate: spec: template: metadata: labels: app: your-periodic-job spec: containers: - name: your_container image: your_image imagePullPolicy: IfNotPresent restartPolicy: OnFailure` Adjust the data of course and let me know if that helped please. – Wytrzymały Wiktor Sep 20 '19 at 12:14

0 Answers0