mirror of https://github.com/harness/drone.git
fix: [CDE-668]: Fixing the usage of last used field in gitspace instance. (#3524)
* Fixing formatting. * fix: [CDE-668]: Fixing the usage of last used field in gitspace instance.try-new-ui
parent
0842b868f5
commit
45d2a72d20
|
@ -151,7 +151,6 @@ func (c *Service) buildGitspaceInstance(config types.GitspaceConfig) (*types.Git
|
|||
Created: now,
|
||||
Updated: now,
|
||||
TotalTimeUsed: 0,
|
||||
LastUsed: &now,
|
||||
}
|
||||
if config.IDE == enum.IDETypeVSCodeWeb || config.IDE == enum.IDETypeVSCode {
|
||||
gitspaceInstance.MachineUser = &gitspaceMachineUser
|
||||
|
|
|
@ -16,7 +16,6 @@ package types
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/harness/gitness/types/enum"
|
||||
)
|
||||
|
@ -125,15 +124,9 @@ func (g *GitspaceInstance) GetGitspaceState() (enum.GitspaceStateType, error) {
|
|||
enum.GitspaceInstanceStateUnknown:
|
||||
return enum.GitspaceStateError, nil
|
||||
case enum.GitspaceInstanceStateStarting:
|
||||
if g.LastUsed != nil && lastUpdateTimeExceeds10Mins(*g.LastUsed) {
|
||||
return enum.GitspaceStateError, nil
|
||||
}
|
||||
return enum.GitspaceStateStarting, nil
|
||||
case enum.GitspaceInstanceStateStopping,
|
||||
enum.GitSpaceInstanceStateCleaning:
|
||||
if g.ActiveTimeEnded != nil && lastUpdateTimeExceeds10Mins(*g.ActiveTimeEnded) {
|
||||
return enum.GitspaceStateError, nil
|
||||
}
|
||||
return enum.GitspaceStateStopping, nil
|
||||
case enum.GitspaceInstanceStateCleaned:
|
||||
return enum.GitspaceStateStopped, nil
|
||||
|
@ -141,8 +134,3 @@ func (g *GitspaceInstance) GetGitspaceState() (enum.GitspaceStateType, error) {
|
|||
return enum.GitspaceStateError, fmt.Errorf("unsupported gitspace instance state %s", string(instanceState))
|
||||
}
|
||||
}
|
||||
|
||||
func lastUpdateTimeExceeds10Mins(lastUpdateTime int64) bool {
|
||||
duration := time.Minute * 10
|
||||
return time.Since(time.UnixMilli(lastUpdateTime)) > duration
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue