mirror of
https://github.com/harness/drone.git
synced 2025-05-08 01:10:27 +08:00
fix: [CDE-202]: update gitspace database funcs (#2809)
* remove named returns * update gitspace database funcs
This commit is contained in:
parent
80dc6ff0b0
commit
7790c19a7f
@ -20,7 +20,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Service) UpdateInstance(
|
func (c *Service) UpdateInstance(
|
||||||
@ -34,16 +33,3 @@ func (c *Service) UpdateInstance(
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Service) UpdateAllStateInstance(
|
|
||||||
ctx context.Context,
|
|
||||||
status enum.GitspaceInstanceStateType,
|
|
||||||
instancesIDs []int64,
|
|
||||||
) error {
|
|
||||||
updatedUnixTime := time.Now().UnixMilli()
|
|
||||||
err := c.gitspaceInstanceStore.BulkUpdateState(ctx, status, updatedUnixTime, instancesIDs)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to update all statue of gitspace instances: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -676,19 +676,11 @@ type (
|
|||||||
// Update tries to update a gitspace instance in the datastore with optimistic locking.
|
// Update tries to update a gitspace instance in the datastore with optimistic locking.
|
||||||
Update(ctx context.Context, gitspaceInstance *types.GitspaceInstance) error
|
Update(ctx context.Context, gitspaceInstance *types.GitspaceInstance) error
|
||||||
|
|
||||||
// BulkUpdateState updates state of given gitspace instance IDs to given state
|
|
||||||
BulkUpdateState(
|
|
||||||
ctx context.Context,
|
|
||||||
state enum.GitspaceInstanceStateType,
|
|
||||||
updateTimeUnix int64,
|
|
||||||
gitspaceInstanceIDs []int64,
|
|
||||||
) error
|
|
||||||
|
|
||||||
// List lists the gitspace instance present in a parent space ID in the datastore.
|
// List lists the gitspace instance present in a parent space ID in the datastore.
|
||||||
List(ctx context.Context, filter *types.GitspaceFilter) ([]*types.GitspaceInstance, error)
|
List(ctx context.Context, filter *types.GitspaceFilter) ([]*types.GitspaceInstance, error)
|
||||||
|
|
||||||
// ListDead lists dead gitspace instances whose heartbeat stopped coming after the given time.
|
// ListDead lists dead gitspace instances whose heartbeat stopped coming after the given time.
|
||||||
ListDead(ctx context.Context, filter *types.GitspaceFilter) (gitInstanceIDs []int64, err error)
|
ListDead(ctx context.Context, filter *types.GitspaceFilter) ([]*types.GitspaceInstance, error)
|
||||||
|
|
||||||
// FetchInactiveGitspaceConfigs lists the inactive gitspace instance present in the datastore
|
// FetchInactiveGitspaceConfigs lists the inactive gitspace instance present in the datastore
|
||||||
FetchInactiveGitspaceConfigs(ctx context.Context, filter *types.GitspaceFilter) ([]int64, error)
|
FetchInactiveGitspaceConfigs(ctx context.Context, filter *types.GitspaceFilter) ([]int64, error)
|
||||||
|
@ -256,32 +256,6 @@ func (g gitspaceInstanceStore) Update(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g gitspaceInstanceStore) BulkUpdateState(
|
|
||||||
ctx context.Context,
|
|
||||||
state enum.GitspaceInstanceStateType,
|
|
||||||
updateTimeUnix int64,
|
|
||||||
gitspaceInstanceIDs []int64,
|
|
||||||
) error {
|
|
||||||
stmt := database.Builder.
|
|
||||||
Update(gitspaceInstanceTable).
|
|
||||||
Set("gits_state", state).
|
|
||||||
Set("gits_updated", updateTimeUnix).
|
|
||||||
Where(squirrel.Eq{"gits_id": gitspaceInstanceIDs})
|
|
||||||
|
|
||||||
sqlStr, args, err := stmt.ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
|
||||||
}
|
|
||||||
|
|
||||||
db := dbtx.GetAccessor(ctx, g.db)
|
|
||||||
if _, err = db.ExecContext(ctx, sqlStr, args...); err != nil {
|
|
||||||
return database.ProcessSQLErrorf(ctx, err,
|
|
||||||
"Failed to update gitspace instances for %v", gitspaceInstanceIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g gitspaceInstanceStore) FindLatestByGitspaceConfigID(
|
func (g gitspaceInstanceStore) FindLatestByGitspaceConfigID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
gitspaceConfigID int64,
|
gitspaceConfigID int64,
|
||||||
@ -333,9 +307,9 @@ func (g gitspaceInstanceStore) List(
|
|||||||
func (g gitspaceInstanceStore) ListDead(
|
func (g gitspaceInstanceStore) ListDead(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
filter *types.GitspaceFilter,
|
filter *types.GitspaceFilter,
|
||||||
) (gitInstanceIDs []int64, err error) {
|
) ([]*types.GitspaceInstance, error) {
|
||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select("gits_id").
|
Select(gitspaceInstanceSelectColumns).
|
||||||
From(gitspaceInstanceTable).
|
From(gitspaceInstanceTable).
|
||||||
Where(squirrel.Lt{"gits_last_heartbeat": filter.LastHeartBeatBefore}).
|
Where(squirrel.Lt{"gits_last_heartbeat": filter.LastHeartBeatBefore}).
|
||||||
Where(squirrel.Eq{"gits_state": filter.State}).
|
Where(squirrel.Eq{"gits_state": filter.State}).
|
||||||
@ -346,11 +320,12 @@ func (g gitspaceInstanceStore) ListDead(
|
|||||||
return nil, errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
return nil, errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gitspaceInstances []*types.GitspaceInstance
|
||||||
db := dbtx.GetAccessor(ctx, g.db)
|
db := dbtx.GetAccessor(ctx, g.db)
|
||||||
if err = db.SelectContext(ctx, &gitInstanceIDs, sqlStr, args...); err != nil {
|
if err = db.SelectContext(ctx, &gitspaceInstances, sqlStr, args...); err != nil {
|
||||||
return nil, database.ProcessSQLErrorf(ctx, err, "Failed executing gitspace instance list query")
|
return nil, database.ProcessSQLErrorf(ctx, err, "Failed executing gitspace instance list query")
|
||||||
}
|
}
|
||||||
return gitInstanceIDs, nil
|
return gitspaceInstances, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g gitspaceInstanceStore) FetchInactiveGitspaceConfigs(
|
func (g gitspaceInstanceStore) FetchInactiveGitspaceConfigs(
|
||||||
|
Loading…
Reference in New Issue
Block a user