mirror of
https://github.com/goharbor/harbor.git
synced 2024-06-26 14:55:06 +02:00
fix: add worker pool for execution sweep to limit workers
Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
parent
cc26d75b56
commit
ed4d9a533e
|
@ -22,6 +22,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
|
"github.com/goharbor/harbor/src/lib"
|
||||||
"github.com/goharbor/harbor/src/lib/errors"
|
"github.com/goharbor/harbor/src/lib/errors"
|
||||||
"github.com/goharbor/harbor/src/lib/log"
|
"github.com/goharbor/harbor/src/lib/log"
|
||||||
"github.com/goharbor/harbor/src/lib/orm"
|
"github.com/goharbor/harbor/src/lib/orm"
|
||||||
|
@ -83,6 +84,7 @@ func NewExecutionManager() ExecutionManager {
|
||||||
taskMgr: Mgr,
|
taskMgr: Mgr,
|
||||||
taskDAO: dao.NewTaskDAO(),
|
taskDAO: dao.NewTaskDAO(),
|
||||||
ormCreator: orm.Crt,
|
ormCreator: orm.Crt,
|
||||||
|
wp: lib.NewWorkerPool(10),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +93,7 @@ type executionManager struct {
|
||||||
taskMgr Manager
|
taskMgr Manager
|
||||||
taskDAO dao.TaskDAO
|
taskDAO dao.TaskDAO
|
||||||
ormCreator orm.Creator
|
ormCreator orm.Creator
|
||||||
|
wp *lib.WorkerPool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *executionManager) Count(ctx context.Context, query *q.Query) (int64, error) {
|
func (e *executionManager) Count(ctx context.Context, query *q.Query) (int64, error) {
|
||||||
|
@ -125,6 +128,8 @@ func (e *executionManager) Create(ctx context.Context, vendorType string, vendor
|
||||||
|
|
||||||
// sweep the execution records to avoid the execution/task records explosion
|
// sweep the execution records to avoid the execution/task records explosion
|
||||||
go func() {
|
go func() {
|
||||||
|
e.wp.GetWorker()
|
||||||
|
defer e.wp.ReleaseWorker()
|
||||||
// as we start a new transaction here to do the sweep work, the current execution record
|
// as we start a new transaction here to do the sweep work, the current execution record
|
||||||
// may be not visible(when the transaction in which the current execution is created
|
// may be not visible(when the transaction in which the current execution is created
|
||||||
// in isn't committed), this will cause that there are one more execution records than expected
|
// in isn't committed), this will cause that there are one more execution records than expected
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
|
"github.com/goharbor/harbor/src/lib"
|
||||||
"github.com/goharbor/harbor/src/lib/errors"
|
"github.com/goharbor/harbor/src/lib/errors"
|
||||||
"github.com/goharbor/harbor/src/lib/q"
|
"github.com/goharbor/harbor/src/lib/q"
|
||||||
"github.com/goharbor/harbor/src/pkg/task/dao"
|
"github.com/goharbor/harbor/src/pkg/task/dao"
|
||||||
|
@ -46,6 +47,7 @@ func (e *executionManagerTestSuite) SetupTest() {
|
||||||
taskMgr: e.taskMgr,
|
taskMgr: e.taskMgr,
|
||||||
taskDAO: e.taskDAO,
|
taskDAO: e.taskDAO,
|
||||||
ormCreator: e.ormCreator,
|
ormCreator: e.ormCreator,
|
||||||
|
wp: lib.NewWorkerPool(10),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user