Skip to content

Commit

Permalink
handle running jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed May 2, 2024
1 parent 0301a69 commit 413c7f3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pkg/health/health_cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

}

0 comments on commit 413c7f3

Please sign in to comment.