mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Fix sql error in FixDanglingStateExecution (#18411)
Fix sql error in fixDanglingStateExecution fixes #18408 Signed-off-by: stonezdj <daojunz@vmware.com>
This commit is contained in:
parent
85bcbbaf62
commit
088d18bccf
@ -200,11 +200,10 @@ func (sm *sweepManager) FixDanglingStateExecution(ctx context.Context) error {
|
||||
ELSE 'Success'
|
||||
END
|
||||
WHERE status = 'Running'
|
||||
AND start_time < now() - INTERVAL ?
|
||||
AND EXTRACT(epoch FROM NOW() - start_time)/3600 > ?
|
||||
AND NOT EXISTS (SELECT 1 FROM task WHERE execution_id = execution.id AND status = 'Running')`
|
||||
|
||||
intervalStr := fmt.Sprintf("%d hour", config.MaxDanglingHour())
|
||||
_, err = ormer.Raw(sql, intervalStr).Exec()
|
||||
_, err = ormer.Raw(sql, config.MaxDanglingHour()).Exec()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to fix dangling state execution")
|
||||
}
|
||||
|
@ -19,14 +19,16 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/pkg/task/dao"
|
||||
htesting "github.com/goharbor/harbor/src/testing"
|
||||
"github.com/goharbor/harbor/src/testing/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type sweepManagerTestSuite struct {
|
||||
suite.Suite
|
||||
htesting.Suite
|
||||
execDao *mockExecutionDAO
|
||||
mgr *sweepManager
|
||||
}
|
||||
@ -36,6 +38,7 @@ func TestSweepManager(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *sweepManagerTestSuite) SetupSuite() {
|
||||
suite.Suite.SetupSuite()
|
||||
suite.execDao = &mockExecutionDAO{}
|
||||
suite.mgr = &sweepManager{execDAO: suite.execDao}
|
||||
}
|
||||
@ -54,3 +57,8 @@ func (suite *sweepManagerTestSuite) TestGetCandidateMaxStartTime() {
|
||||
suite.NoError(err, "should not got error")
|
||||
suite.Equal(now.String(), startTime.String())
|
||||
}
|
||||
|
||||
func (suite *sweepManagerTestSuite) Test_sweepManager_FixDanglingStateExecution() {
|
||||
err := suite.mgr.FixDanglingStateExecution(suite.Context())
|
||||
suite.NoError(err, "should not got error")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user