From 413c7f3afa7f651c98c7e78296626faf2688f578 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 2 May 2024 13:28:17 +0545 Subject: [PATCH] handle running jobs --- pkg/health/health_cronjob.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/health/health_cronjob.go b/pkg/health/health_cronjob.go index d1dfde2..407cb0a 100644 --- a/pkg/health/health_cronjob.go +++ b/pkg/health/health_cronjob.go @@ -39,15 +39,6 @@ func getBatchv1CronJobHealth(job *batchv1.CronJob) (*HealthStatus, error) { }, nil } - if job.Status.LastSuccessfulTime.Before(job.Status.LastScheduleTime) { - return &HealthStatus{ - Ready: true, // The cronjob did in fact run - Health: HealthUnhealthy, - Status: HealthStatusError, - Message: "Last run failed, last successful run was" + job.Status.LastSuccessfulTime.Format("2006-01-02 15:04:05 -0700"), - }, nil - } - if len(job.Status.Active) > 0 { return &HealthStatus{ Ready: true, @@ -57,11 +48,19 @@ func getBatchv1CronJobHealth(job *batchv1.CronJob) (*HealthStatus, error) { }, nil } + if job.Status.LastSuccessfulTime.Before(job.Status.LastScheduleTime) { + return &HealthStatus{ + Ready: true, // The cronjob did in fact run + Health: HealthUnhealthy, + Status: HealthStatusError, + Message: "Last run failed, last successful run was" + job.Status.LastSuccessfulTime.Format("2006-01-02 15:04:05 -0700"), + }, nil + } + return &HealthStatus{ Ready: true, Health: HealthHealthy, Status: HealthStatusCompleted, Message: fmt.Sprintf("Last run at %s in %s", job.Status.LastScheduleTime.Format("2006-01-02 15:04:05 -0700"), job.Status.LastSuccessfulTime.Sub(job.Status.LastScheduleTime.Time)), }, nil - }