summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-10-02 14:15:51 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2017-10-02 09:15:51 -0400
commit078467ee96bdc74cc385810a24eeae2a2318be46 (patch)
tree0341c62a9374e166522688d309be4b7cf9a73a4c /store
parent76bd1bb212177824379c485c553e54530a854009 (diff)
downloadchat-078467ee96bdc74cc385810a24eeae2a2318be46.tar.gz
chat-078467ee96bdc74cc385810a24eeae2a2318be46.tar.bz2
chat-078467ee96bdc74cc385810a24eeae2a2318be46.zip
PLT-7759: Make GetNewestJobByStatusAndType not fail when no jobs match. (#7540)
Diffstat (limited to 'store')
-rw-r--r--store/sqlstore/job_store.go4
-rw-r--r--store/sqlstore/job_store_test.go4
2 files changed, 6 insertions, 2 deletions
diff --git a/store/sqlstore/job_store.go b/store/sqlstore/job_store.go
index 0ae5a6a07..8cd921217 100644
--- a/store/sqlstore/job_store.go
+++ b/store/sqlstore/job_store.go
@@ -344,8 +344,8 @@ func (jss SqlJobStore) GetNewestJobByStatusAndType(status string, jobType string
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)
+ LIMIT 1`, map[string]interface{}{"Status": status, "Type": jobType}); err != nil && err != sql.ErrNoRows {
+ result.Err = model.NewAppError("SqlJobStore.GetNewestJobByStatusAndType", "store.sql_job.get_newest_job_by_status_and_type.app_error", nil, "Status="+status+", "+err.Error(), http.StatusInternalServerError)
} else {
result.Data = job
}
diff --git a/store/sqlstore/job_store_test.go b/store/sqlstore/job_store_test.go
index 148d8b92d..38686c4e5 100644
--- a/store/sqlstore/job_store_test.go
+++ b/store/sqlstore/job_store_test.go
@@ -275,6 +275,10 @@ func TestJobStoreGetNewestJobByStatusAndType(t *testing.T) {
result := <-ss.Job().GetNewestJobByStatusAndType(status1, jobType1)
assert.Nil(t, result.Err)
assert.EqualValues(t, jobs[0].Id, result.Data.(*model.Job).Id)
+
+ result = <-ss.Job().GetNewestJobByStatusAndType(model.NewId(), model.NewId())
+ assert.Nil(t, result.Err)
+ assert.Nil(t, result.Data.(*model.Job))
}
func TestJobStoreGetCountByStatusAndType(t *testing.T) {