diff options
author | George Goldberg <george@gberg.me> | 2017-09-28 17:11:13 +0100 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-09-28 09:11:13 -0700 |
commit | a06830b2f88a8d374c326a1191870cbc7cf7dac2 (patch) | |
tree | 4879ce49de061fba894fe01b54db701c639f0e94 /store/sqlstore/job_store.go | |
parent | f263d2b9510fb557fe075dee5097cb32e2b1e5e2 (diff) | |
download | chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.tar.gz chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.tar.bz2 chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.zip |
PLT-7644: Improve job scheduler architecture. (#7532)
Diffstat (limited to 'store/sqlstore/job_store.go')
-rw-r--r-- | store/sqlstore/job_store.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/store/sqlstore/job_store.go b/store/sqlstore/job_store.go index c56f526af..0ae5a6a07 100644 --- a/store/sqlstore/job_store.go +++ b/store/sqlstore/job_store.go @@ -325,6 +325,64 @@ func (jss SqlJobStore) GetAllByStatus(status string) store.StoreChannel { return storeChannel } +func (jss SqlJobStore) GetNewestJobByStatusAndType(status string, jobType string) store.StoreChannel { + storeChannel := make(store.StoreChannel, 1) + + go func() { + result := store.StoreResult{} + + var job *model.Job + + if err := jss.GetReplica().SelectOne(&job, + `SELECT + * + FROM + Jobs + WHERE + Status = :Status + AND + Type = :Type + ORDER BY + CreateAt DESC + LIMIT 1`, map[string]interface{}{"Status": status, "Type": jobType}); err != nil { + result.Err = model.NewAppError("SqlJobStore.GetAllByStatus", "store.sql_job.get_newest_job_by_status_and_type.app_error", nil, "Status="+status+", "+err.Error(), http.StatusInternalServerError) + } else { + result.Data = job + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + +func (jss SqlJobStore) GetCountByStatusAndType(status string, jobType string) store.StoreChannel { + storeChannel := make(store.StoreChannel, 1) + + go func() { + result := store.StoreResult{} + + if count, err := jss.GetReplica().SelectInt(`SELECT + COUNT(*) + FROM + Jobs + WHERE + Status = :Status + AND + Type = :Type`, map[string]interface{}{"Status": status, "Type": jobType}); err != nil { + result.Err = model.NewAppError("SqlJobStore.GetCountByStatusAndType", "store.sql_job.get_count_by_status_and_type.app_error", nil, "Status="+status+", "+err.Error(), http.StatusInternalServerError) + } else { + result.Data = count + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (jss SqlJobStore) Delete(id string) store.StoreChannel { storeChannel := make(store.StoreChannel, 1) |