mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
Fix gc api issues
1, filter out the scan all jobs in the gc list. 2, make it able to delete unexecuted scheduler. Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
d1981d23b1
commit
a4ad4c7282
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user