mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
Merge pull request #14012 from ywk253100/210113_replication
Query executions with both vendor type and ID when sweep the execution records
This commit is contained in:
commit
c3b986cbcd
@ -116,12 +116,22 @@ func (c *controller) Stop(ctx context.Context, id int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) ExecutionCount(ctx context.Context, query *q.Query) (int64, error) {
|
func (c *controller) ExecutionCount(ctx context.Context, query *q.Query) (int64, error) {
|
||||||
query = q.MustClone(query)
|
return c.execMgr.Count(ctx, c.buildExecutionQuery(query))
|
||||||
query.Keywords["VendorType"] = job.Replication
|
|
||||||
return c.execMgr.Count(ctx, query)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) ListExecutions(ctx context.Context, query *q.Query) ([]*Execution, error) {
|
func (c *controller) ListExecutions(ctx context.Context, query *q.Query) ([]*Execution, error) {
|
||||||
|
execs, err := c.execMgr.List(ctx, c.buildExecutionQuery(query))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var executions []*Execution
|
||||||
|
for _, exec := range execs {
|
||||||
|
executions = append(executions, convertExecution(exec))
|
||||||
|
}
|
||||||
|
return executions, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *controller) buildExecutionQuery(query *q.Query) *q.Query {
|
||||||
// as the following logic may change the content of the query, clone it first
|
// as the following logic may change the content of the query, clone it first
|
||||||
query = q.MustClone(query)
|
query = q.MustClone(query)
|
||||||
query.Keywords["VendorType"] = job.Replication
|
query.Keywords["VendorType"] = job.Replication
|
||||||
@ -134,16 +144,7 @@ func (c *controller) ListExecutions(ctx context.Context, query *q.Query) ([]*Exe
|
|||||||
query.Keywords["VendorID"] = value
|
query.Keywords["VendorID"] = value
|
||||||
delete(query.Keywords, "policy_id")
|
delete(query.Keywords, "policy_id")
|
||||||
}
|
}
|
||||||
|
return query
|
||||||
execs, err := c.execMgr.List(ctx, query)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var executions []*Execution
|
|
||||||
for _, exec := range execs {
|
|
||||||
executions = append(executions, convertExecution(exec))
|
|
||||||
}
|
|
||||||
return executions, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) GetExecution(ctx context.Context, id int64) (*Execution, error) {
|
func (c *controller) GetExecution(ctx context.Context, id int64) (*Execution, error) {
|
||||||
|
@ -123,8 +123,11 @@ 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() {
|
||||||
|
// 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
|
||||||
|
// in isn't committed), this will cause that there are one more execution records than expected
|
||||||
ctx := orm.NewContext(context.Background(), e.ormCreator.Create())
|
ctx := orm.NewContext(context.Background(), e.ormCreator.Create())
|
||||||
if err := e.sweep(ctx, vendorType); err != nil {
|
if err := e.sweep(ctx, vendorType, vendorID); err != nil {
|
||||||
log.Errorf("failed to sweep the executions of %s: %v", vendorType, err)
|
log.Errorf("failed to sweep the executions of %s: %v", vendorType, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -133,7 +136,7 @@ func (e *executionManager) Create(ctx context.Context, vendorType string, vendor
|
|||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *executionManager) sweep(ctx context.Context, vendorType string) error {
|
func (e *executionManager) sweep(ctx context.Context, vendorType string, vendorID int64) error {
|
||||||
count := executionSweeperCount[vendorType]
|
count := executionSweeperCount[vendorType]
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
count = defaultExecutionSweeperCount
|
count = defaultExecutionSweeperCount
|
||||||
@ -146,6 +149,7 @@ func (e *executionManager) sweep(ctx context.Context, vendorType string) error {
|
|||||||
executions, err := e.List(ctx, &q.Query{
|
executions, err := e.List(ctx, &q.Query{
|
||||||
Keywords: map[string]interface{}{
|
Keywords: map[string]interface{}{
|
||||||
"VendorType": vendorType,
|
"VendorType": vendorType,
|
||||||
|
"VendorID": vendorID,
|
||||||
},
|
},
|
||||||
PageNumber: 2,
|
PageNumber: 2,
|
||||||
PageSize: int64(count),
|
PageSize: int64(count),
|
||||||
|
Loading…
Reference in New Issue
Block a user