Merge pull request #6003 from wy65701436/fix-gc-bug

Fix gc api issues
This commit is contained in:
Wenkai Yin 2018-10-11 10:26:38 +08:00 committed by GitHub
commit 83147b1982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -87,12 +87,19 @@ func SetAdminJobUUID(id int64, uuid string) error {
return err
}
// GetTop10AdminJobs ...
func GetTop10AdminJobs() ([]*models.AdminJob, error) {
sql := `select * from admin_job
where deleted = false order by update_time desc limit 10`
// GetTop10AdminJobsOfName ...
func GetTop10AdminJobsOfName(name string) ([]*models.AdminJob, error) {
o := GetOrmer()
jobs := []*models.AdminJob{}
_, err := GetOrmer().Raw(sql).QueryRows(&jobs)
n, err := o.Raw(`select * from admin_job
where deleted = false and job_name = ? order by update_time desc limit 10`, name).QueryRows(&jobs)
if err != nil {
return nil, err
}
if n == 0 {
return nil, nil
}
return jobs, err
}

View File

@ -70,6 +70,6 @@ func TestAddAdminJob(t *testing.T) {
_, err = AddAdminJob(job)
require.Nil(t, err)
jobs, _ = GetTop10AdminJobs()
assert.Equal(t, len(jobs), 3)
jobs, _ = GetTop10AdminJobsOfName("job")
assert.Equal(t, len(jobs), 2)
}

View File

@ -131,7 +131,7 @@ func (gc *GCAPI) GetGC() {
// List ...
func (gc *GCAPI) List() {
jobs, err := dao.GetTop10AdminJobs()
jobs, err := dao.GetTop10AdminJobsOfName(common_job.ImageGC)
if err != nil {
gc.HandleInternalServerError(fmt.Sprintf("failed to get admin jobs: %v", err))
return
@ -251,7 +251,7 @@ func (gc *GCAPI) submitJob(gr *models.GCReq) {
// submit job to jobservice
log.Debugf("submiting GC admin job to jobservice")
_, err = utils_core.GetJobServiceClient().SubmitJob(job)
uuid, err := utils_core.GetJobServiceClient().SubmitJob(job)
if err != nil {
if err := dao.DeleteAdminJob(id); err != nil {
log.Debugf("Failed to delete admin job, err: %v", err)
@ -259,6 +259,10 @@ func (gc *GCAPI) submitJob(gr *models.GCReq) {
gc.HandleInternalServerError(fmt.Sprintf("%v", err))
return
}
if err := dao.SetAdminJobUUID(id, uuid); err != nil {
gc.HandleInternalServerError(fmt.Sprintf("%v", err))
return
}
}
func convertToGCRep(job *common_models.AdminJob) (models.GCRep, error) {