Этот коммит содержится в:
Chris
2017-10-06 08:12:10 -07:00
коммит произвёл Joram Wilander
родитель 12501673d0
Коммит 363568b4eb
35 изменённых файлов: 589 добавлений и 3269 удалений

Просмотреть файл

@@ -35,29 +35,17 @@ func (jss SqlJobStore) CreateIndexesIfNotExists() {
}
func (jss SqlJobStore) Save(job *model.Job) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
if err := jss.GetMaster().Insert(job); err != nil {
result.Err = model.NewAppError("SqlJobStore.Save", "store.sql_job.save.app_error", nil, "id="+job.Id+", "+err.Error(), http.StatusInternalServerError)
} else {
result.Data = job
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) UpdateOptimistically(job *model.Job, currentStatus string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
if sqlResult, err := jss.GetMaster().Exec(
`UPDATE
Jobs
@@ -92,20 +80,11 @@ func (jss SqlJobStore) UpdateOptimistically(job *model.Job, currentStatus string
}
}
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) UpdateStatus(id string, status string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
job := &model.Job{
Id: id,
Status: status,
@@ -121,20 +100,11 @@ func (jss SqlJobStore) UpdateStatus(id string, status string) store.StoreChannel
if result.Err == nil {
result.Data = job
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) UpdateStatusOptimistically(id string, currentStatus string, newStatus string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var startAtClause string
if newStatus == model.JOB_STATUS_IN_PROGRESS {
startAtClause = `StartAt = :StartAt,`
@@ -164,20 +134,11 @@ func (jss SqlJobStore) UpdateStatusOptimistically(id string, currentStatus strin
}
}
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) Get(id string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var status *model.Job
if err := jss.GetReplica().SelectOne(&status,
@@ -195,20 +156,11 @@ func (jss SqlJobStore) Get(id string) store.StoreChannel {
} else {
result.Data = status
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) GetAllPage(offset int, limit int) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var statuses []*model.Job
if _, err := jss.GetReplica().Select(&statuses,
@@ -226,20 +178,11 @@ func (jss SqlJobStore) GetAllPage(offset int, limit int) store.StoreChannel {
} else {
result.Data = statuses
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) GetAllByType(jobType string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var statuses []*model.Job
if _, err := jss.GetReplica().Select(&statuses,
@@ -255,20 +198,11 @@ func (jss SqlJobStore) GetAllByType(jobType string) store.StoreChannel {
} else {
result.Data = statuses
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) GetAllByTypePage(jobType string, offset int, limit int) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var statuses []*model.Job
if _, err := jss.GetReplica().Select(&statuses,
@@ -288,20 +222,11 @@ func (jss SqlJobStore) GetAllByTypePage(jobType string, offset int, limit int) s
} else {
result.Data = statuses
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) GetAllByStatus(status string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var statuses []*model.Job
if _, err := jss.GetReplica().Select(&statuses,
@@ -317,20 +242,11 @@ func (jss SqlJobStore) GetAllByStatus(status string) store.StoreChannel {
} else {
result.Data = statuses
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) GetNewestJobByStatusAndType(status string, jobType string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var job *model.Job
if err := jss.GetReplica().SelectOne(&job,
@@ -349,20 +265,11 @@ func (jss SqlJobStore) GetNewestJobByStatusAndType(status string, jobType string
} 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{}
return store.Do(func(result *store.StoreResult) {
if count, err := jss.GetReplica().SelectInt(`SELECT
COUNT(*)
FROM
@@ -375,20 +282,11 @@ func (jss SqlJobStore) GetCountByStatusAndType(status string, jobType string) st
} else {
result.Data = count
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (jss SqlJobStore) Delete(id string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
if _, err := jss.GetMaster().Exec(
`DELETE FROM
Jobs
@@ -398,10 +296,5 @@ func (jss SqlJobStore) Delete(id string) store.StoreChannel {
} else {
result.Data = id
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}