mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 10:45:45 +01:00
Print stack trace when recover from panic and print warning message rather than returning an error when updating 0 records
This commit is contained in:
parent
0abd30f9f4
commit
43489c2b67
@ -16,8 +16,8 @@ package dao
|
||||
|
||||
import (
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -35,12 +35,10 @@ func SetClairVulnTimestamp(namespace string, timestamp time.Time) error {
|
||||
if !created {
|
||||
rec.LastUpdate = timestamp
|
||||
n, err := o.Update(rec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return fmt.Errorf("No record is updated, record: %v", *rec)
|
||||
log.Warningf("no records are updated for %v", *rec)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/vmware/harbor/src/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/vmware/harbor/src/common"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
"github.com/vmware/harbor/src/common/utils"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
@ -1531,8 +1531,6 @@ func TestUpdateScanJobStatus(t *testing.T) {
|
||||
j, err := GetScanJob(id)
|
||||
assert.Nil(err)
|
||||
assert.Equal("newstatus", j.Status)
|
||||
err = UpdateScanJobStatus(id+9, "newstatus")
|
||||
assert.NotNil(err)
|
||||
err = ClearTable(models.ScanJobTable)
|
||||
assert.Nil(err)
|
||||
}
|
||||
@ -1632,7 +1630,6 @@ func TestGetScanJobsByStatus(t *testing.T) {
|
||||
assert.Equal(sj1.Repository, r2[0].Repository)
|
||||
}
|
||||
|
||||
|
||||
func TestSaveConfigEntries(t *testing.T) {
|
||||
configEntries := []models.ConfigEntry{
|
||||
{
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
)
|
||||
|
||||
// AddRepTarget ...
|
||||
@ -397,9 +398,9 @@ func UpdateRepJobStatus(id int64, status string) error {
|
||||
Status: status,
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
num, err := o.Update(&j, "Status", "UpdateTime")
|
||||
if num == 0 {
|
||||
err = fmt.Errorf("Failed to update replication job with id: %d %s", id, err.Error())
|
||||
n, err := o.Update(&j, "Status", "UpdateTime")
|
||||
if n == 0 {
|
||||
log.Warningf("no records are updated when updating replication job %d", id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package dao
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -78,7 +79,7 @@ func UpdateScanJobStatus(id int64, status string) error {
|
||||
}
|
||||
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)
|
||||
log.Warningf("no records are updated when updating scan job %d", id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -109,8 +110,9 @@ func SetScanJobForImg(digest string, jobID int64) error {
|
||||
rec.UpdateTime = time.Now()
|
||||
n, err := o.Update(rec, "JobID", "UpdateTime")
|
||||
if n == 0 {
|
||||
return fmt.Errorf("Failed to set scan job for image with digest: %s, error: %v", digest, err)
|
||||
log.Warningf("no records are updated when setting scan job for image with digest %s", digest)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package job
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
@ -80,7 +81,7 @@ func (sm *SM) Start(s string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
sm.Logger.Errorf("Panic: %v, entering error state", r)
|
||||
log.Warningf("Panic when handling job: %v, panic: %v, entering error state", sm.CurrentJob, r)
|
||||
log.Warningf("Panic when handling job: %v, panic: %v \n %s \n, entering error state", sm.CurrentJob, r, debug.Stack())
|
||||
sm.EnterState(models.JobError)
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user