fix golin, add update status

This commit is contained in:
Tan Jiang 2017-05-11 23:47:12 +08:00
parent dcbfb4d309
commit 7d7d0c48f4
2 changed files with 35 additions and 0 deletions

View File

@ -1709,3 +1709,19 @@ func TestGetScanJobs(t *testing.T) {
err = clearTable(ScanJobTable)
assert.Nil(err)
}
func TestUpdateScanJobStatus(t *testing.T) {
assert := assert.New(t)
id, err := AddScanJob(sj1)
assert.Nil(err)
err = UpdateScanJobStatus(id, "newstatus")
assert.Nil(err)
j, err := GetScanJob(id)
assert.Nil(err)
assert.Equal("newstatus", j.Status)
err = UpdateScanJobStatus(id+9, "newstatus")
assert.NotNil(err)
err = clearTable(ScanJobTable)
assert.Nil(err)
}

View File

@ -17,8 +17,12 @@ package dao
import (
"github.com/astaxie/beego/orm"
"github.com/vmware/harbor/src/common/models"
"fmt"
"time"
)
// ScanJobTable is the table name of scan jobs.
const ScanJobTable = "img_scan_job"
// AddScanJob ...
@ -52,6 +56,21 @@ func GetScanJobsByDigest(digest string, limit ...int) ([]*models.ScanJob, error)
return res, err
}
// UpdateScanJobStatus updates the status of a scan job.
func UpdateScanJobStatus(id int64, status string) error {
o := GetOrmer()
sj := models.ScanJob{
ID: id,
Status: status,
UpdateTime: time.Now(),
}
n, err := o.Update(&sj, "Status", "UpdateTime")
if n == 0 {
return fmt.Errorf("Failed to update scan job with id: %d, error: %v", id, err)
}
return err
}
func scanJobQs(limit ...int) orm.QuerySeter {
o := GetOrmer()
l := -1