mirror of
https://github.com/harness/drone.git
synced 2025-05-04 14:12:15 +08:00
feat: [CDE-336]: update heartbeat for gitspace instance (#2742)
* feat: [CDE-336]: update heartbeat for gitspace instance * feat: [CDE-336]: update heartbeat for gitspace instance * feat: [CDE-336]: update heartbeat for gitspace instance * feat: [CDE-336]: update heartbeat for gitspace instance * feat: [CDE-336]: update heartbeat for gitspace instance * feat: [CDE-336]: update heartbeat for gitspace instance * feat: [CDE-336]: update heartbeat for gitspace instance
This commit is contained in:
parent
9f38e07bf3
commit
827305afdb
@ -400,7 +400,8 @@ func (o orchestrator) ResumeStartGitspace(
|
|||||||
ideURLString := ideURL.String()
|
ideURLString := ideURL.String()
|
||||||
gitspaceInstance.URL = &ideURLString
|
gitspaceInstance.URL = &ideURLString
|
||||||
|
|
||||||
gitspaceInstance.LastUsed = time.Now().UnixMilli()
|
lastUsed := time.Now().UnixMilli()
|
||||||
|
gitspaceInstance.LastUsed = &lastUsed
|
||||||
gitspaceInstance.State = enum.GitspaceInstanceStateRunning
|
gitspaceInstance.State = enum.GitspaceInstanceStateRunning
|
||||||
|
|
||||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeGitspaceActionStartCompleted)
|
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeGitspaceActionStartCompleted)
|
||||||
|
@ -49,7 +49,8 @@ const (
|
|||||||
gits_access_type,
|
gits_access_type,
|
||||||
gits_machine_user,
|
gits_machine_user,
|
||||||
gits_uid,
|
gits_uid,
|
||||||
gits_access_key_ref`
|
gits_access_key_ref,
|
||||||
|
gits_last_heartbeat`
|
||||||
gitspaceInstanceSelectColumns = "gits_id," + gitspaceInstanceInsertColumns
|
gitspaceInstanceSelectColumns = "gits_id," + gitspaceInstanceInsertColumns
|
||||||
gitspaceInstanceTable = `gitspaces`
|
gitspaceInstanceTable = `gitspaces`
|
||||||
)
|
)
|
||||||
@ -63,7 +64,7 @@ type gitspaceInstance struct {
|
|||||||
UserUID string `db:"gits_user_uid"`
|
UserUID string `db:"gits_user_uid"`
|
||||||
ResourceUsage null.String `db:"gits_resource_usage"`
|
ResourceUsage null.String `db:"gits_resource_usage"`
|
||||||
SpaceID int64 `db:"gits_space_id"`
|
SpaceID int64 `db:"gits_space_id"`
|
||||||
LastUsed int64 `db:"gits_last_used"`
|
LastUsed null.Int `db:"gits_last_used"`
|
||||||
TotalTimeUsed int64 `db:"gits_total_time_used"`
|
TotalTimeUsed int64 `db:"gits_total_time_used"`
|
||||||
TrackedChanges null.String `db:"gits_tracked_changes"`
|
TrackedChanges null.String `db:"gits_tracked_changes"`
|
||||||
AccessType enum.GitspaceAccessType `db:"gits_access_type"`
|
AccessType enum.GitspaceAccessType `db:"gits_access_type"`
|
||||||
@ -72,6 +73,7 @@ type gitspaceInstance struct {
|
|||||||
Identifier string `db:"gits_uid"`
|
Identifier string `db:"gits_uid"`
|
||||||
Created int64 `db:"gits_created"`
|
Created int64 `db:"gits_created"`
|
||||||
Updated int64 `db:"gits_updated"`
|
Updated int64 `db:"gits_updated"`
|
||||||
|
LastHeartbeat null.Int `db:"gits_last_heartbeat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGitspaceInstanceStore returns a new GitspaceInstanceStore.
|
// NewGitspaceInstanceStore returns a new GitspaceInstanceStore.
|
||||||
@ -89,7 +91,7 @@ func (g gitspaceInstanceStore) Find(ctx context.Context, id int64) (*types.Gitsp
|
|||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select(gitspaceInstanceSelectColumns).
|
Select(gitspaceInstanceSelectColumns).
|
||||||
From(gitspaceInstanceTable).
|
From(gitspaceInstanceTable).
|
||||||
Where("gits_id = $1", id)
|
Where("gits_id = ?", id)
|
||||||
|
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -110,7 +112,7 @@ func (g gitspaceInstanceStore) FindByIdentifier(
|
|||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select(gitspaceInstanceSelectColumns).
|
Select(gitspaceInstanceSelectColumns).
|
||||||
From(gitspaceInstanceTable).
|
From(gitspaceInstanceTable).
|
||||||
Where("gits_uid = $1", identifier)
|
Where("gits_uid = ?", identifier)
|
||||||
|
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -144,6 +146,7 @@ func (g gitspaceInstanceStore) Create(ctx context.Context, gitspaceInstance *typ
|
|||||||
gitspaceInstance.MachineUser,
|
gitspaceInstance.MachineUser,
|
||||||
gitspaceInstance.Identifier,
|
gitspaceInstance.Identifier,
|
||||||
gitspaceInstance.AccessKeyRef,
|
gitspaceInstance.AccessKeyRef,
|
||||||
|
gitspaceInstance.LastHeartbeat,
|
||||||
).
|
).
|
||||||
Suffix(ReturningClause + "gits_id")
|
Suffix(ReturningClause + "gits_id")
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
@ -166,9 +169,10 @@ func (g gitspaceInstanceStore) Update(
|
|||||||
Update(gitspaceInstanceTable).
|
Update(gitspaceInstanceTable).
|
||||||
Set("gits_state", gitspaceInstance.State).
|
Set("gits_state", gitspaceInstance.State).
|
||||||
Set("gits_last_used", gitspaceInstance.LastUsed).
|
Set("gits_last_used", gitspaceInstance.LastUsed).
|
||||||
|
Set("gits_last_heartbeat", gitspaceInstance.LastHeartbeat).
|
||||||
Set("gits_url", gitspaceInstance.URL).
|
Set("gits_url", gitspaceInstance.URL).
|
||||||
Set("gits_updated", gitspaceInstance.Updated).
|
Set("gits_updated", gitspaceInstance.Updated).
|
||||||
Where("gits_id = $5", gitspaceInstance.ID)
|
Where("gits_id = ?", gitspaceInstance.ID)
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
return errors.Wrap(err, "Failed to convert squirrel builder to sql")
|
||||||
@ -188,7 +192,7 @@ func (g gitspaceInstanceStore) FindLatestByGitspaceConfigID(
|
|||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select(gitspaceInstanceSelectColumns).
|
Select(gitspaceInstanceSelectColumns).
|
||||||
From(gitspaceInstanceTable).
|
From(gitspaceInstanceTable).
|
||||||
Where("gits_gitspace_config_id = $1", gitspaceConfigID).
|
Where("gits_gitspace_config_id = ?", gitspaceConfigID).
|
||||||
OrderBy("gits_created DESC")
|
OrderBy("gits_created DESC")
|
||||||
|
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
@ -272,7 +276,7 @@ func (g gitspaceInstanceStore) mapToGitspaceInstance(
|
|||||||
State: in.State,
|
State: in.State,
|
||||||
UserID: in.UserUID,
|
UserID: in.UserUID,
|
||||||
ResourceUsage: in.ResourceUsage.Ptr(),
|
ResourceUsage: in.ResourceUsage.Ptr(),
|
||||||
LastUsed: in.LastUsed,
|
LastUsed: in.LastUsed.Ptr(),
|
||||||
TotalTimeUsed: in.TotalTimeUsed,
|
TotalTimeUsed: in.TotalTimeUsed,
|
||||||
TrackedChanges: in.TrackedChanges.Ptr(),
|
TrackedChanges: in.TrackedChanges.Ptr(),
|
||||||
AccessType: in.AccessType,
|
AccessType: in.AccessType,
|
||||||
@ -281,6 +285,7 @@ func (g gitspaceInstanceStore) mapToGitspaceInstance(
|
|||||||
SpaceID: in.SpaceID,
|
SpaceID: in.SpaceID,
|
||||||
Created: in.Created,
|
Created: in.Created,
|
||||||
Updated: in.Updated,
|
Updated: in.Updated,
|
||||||
|
LastHeartbeat: in.LastHeartbeat.Ptr(),
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE gitspaces DROP COLUMN gits_last_heartbeat;
|
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE gitspaces ADD COLUMN gits_last_heartbeat BIGINT;
|
||||||
|
ALTER TABLE gitspaces ALTER COLUMN gits_last_used DROP NOT NULL;
|
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE gitspaces DROP COLUMN gits_last_heartbeat;
|
@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE gitspaces ADD COLUMN gits_last_heartbeat BIGINT;
|
||||||
|
ALTER TABLE gitspaces DROP COLUMN gits_last_used;
|
||||||
|
ALTER TABLE gitspaces ADD COLUMN gits_last_used int64 NULL;
|
@ -62,7 +62,7 @@ type GitspaceInstance struct {
|
|||||||
State enum.GitspaceInstanceStateType `json:"state"`
|
State enum.GitspaceInstanceStateType `json:"state"`
|
||||||
UserID string `json:"-"`
|
UserID string `json:"-"`
|
||||||
ResourceUsage *string `json:"resource_usage"`
|
ResourceUsage *string `json:"resource_usage"`
|
||||||
LastUsed int64 `json:"last_used,omitempty"`
|
LastUsed *int64 `json:"last_used,omitempty"`
|
||||||
TotalTimeUsed int64 `json:"total_time_used"`
|
TotalTimeUsed int64 `json:"total_time_used"`
|
||||||
TrackedChanges *string `json:"tracked_changes"`
|
TrackedChanges *string `json:"tracked_changes"`
|
||||||
AccessKey *string `json:"access_key,omitempty"`
|
AccessKey *string `json:"access_key,omitempty"`
|
||||||
@ -73,6 +73,7 @@ type GitspaceInstance struct {
|
|||||||
SpaceID int64 `json:"-"`
|
SpaceID int64 `json:"-"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
Updated int64 `json:"updated"`
|
Updated int64 `json:"updated"`
|
||||||
|
LastHeartbeat *int64 `json:"last_heartbeat,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GitspaceFilter struct {
|
type GitspaceFilter struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user