summaryrefslogtreecommitdiffstats
path: root/jobs/jobs.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-09-28 17:11:13 +0100
committerCorey Hulen <corey@hulen.com>2017-09-28 09:11:13 -0700
commita06830b2f88a8d374c326a1191870cbc7cf7dac2 (patch)
tree4879ce49de061fba894fe01b54db701c639f0e94 /jobs/jobs.go
parentf263d2b9510fb557fe075dee5097cb32e2b1e5e2 (diff)
downloadchat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.tar.gz
chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.tar.bz2
chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.zip
PLT-7644: Improve job scheduler architecture. (#7532)
Diffstat (limited to 'jobs/jobs.go')
-rw-r--r--jobs/jobs.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/jobs/jobs.go b/jobs/jobs.go
index a51780865..22d87e850 100644
--- a/jobs/jobs.go
+++ b/jobs/jobs.go
@@ -141,3 +141,29 @@ func CancellationWatcher(ctx context.Context, jobId string, cancelChan chan inte
}
}
}
+
+func GenerateNextStartDateTime(now time.Time, nextStartTime time.Time) *time.Time {
+ nextTime := time.Date(now.Year(), now.Month(), now.Day(), nextStartTime.Hour(), nextStartTime.Minute(), 0, 0, time.Local)
+
+ if !now.Before(nextTime) {
+ nextTime = nextTime.AddDate(0, 0, 1)
+ }
+
+ return &nextTime
+}
+
+func CheckForPendingJobsByType(jobType string) (bool, *model.AppError) {
+ if result := <-Srv.Store.Job().GetCountByStatusAndType(model.JOB_STATUS_PENDING, jobType); result.Err != nil {
+ return false, result.Err
+ } else {
+ return result.Data.(int64) > 0, nil
+ }
+}
+
+func GetLastSuccessfulJobByType(jobType string) (*model.Job, *model.AppError) {
+ if result := <-Srv.Store.Job().GetNewestJobByStatusAndType(model.JOB_STATUS_SUCCESS, jobType); result.Err != nil {
+ return nil, result.Err
+ } else {
+ return result.Data.(*model.Job), nil
+ }
+}