마지막 배포 상태 항상 유지 + timestamp

This commit is contained in:
2023-10-26 13:53:36 +09:00
parent 282ef95ab0
commit 22148f8ae7
3 changed files with 55 additions and 23 deletions

View File

@ -6,6 +6,7 @@ import (
"reflect"
"strings"
"sync"
"time"
"repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/houston/shared/protos"
@ -59,16 +60,21 @@ type hostPool struct {
hosts map[string]*hostWithChan
}
type deployingBoard struct {
sync.Mutex
progs []*protos.DeployingProgress
type deployingProgress struct {
*protos.DeployingProgress
Timestamp int64
}
func (db *deployingBoard) clone() (out []*protos.DeployingProgress) {
type deployingBoard struct {
sync.Mutex
progs []deployingProgress
}
func (db *deployingBoard) clone() (out []deployingProgress) {
db.Lock()
defer db.Unlock()
out = make([]*protos.DeployingProgress, len(db.progs))
out = make([]deployingProgress, len(db.progs))
copy(out, db.progs)
return
}
@ -211,16 +217,16 @@ func (os *operationServer) ReportDeployingProgress(ctx context.Context, dp *prot
for i, p := range os.db.progs {
if p.Hostname == dp.Hostname && p.Name == dp.Name && p.Version == dp.Version {
if dp.State == "done" {
os.db.progs = append(os.db.progs[:i], os.db.progs[i+1:]...)
} else {
os.db.progs[i] = dp
}
os.db.progs[i].DeployingProgress = dp
os.db.progs[i].Timestamp = time.Now().UTC().Unix()
return &protos.Empty{}, nil
}
}
os.db.progs = append(os.db.progs, dp)
os.db.progs = append(os.db.progs, deployingProgress{
DeployingProgress: dp,
Timestamp: time.Now().UTC().Unix(),
})
return &protos.Empty{}, nil
}
@ -253,12 +259,29 @@ func (os *operationServer) Deploy(d DeployRequest) {
})
}
for _, t := range targets {
dps := make([]deployingProgress, len(targets))
now := time.Now().UTC().Unix()
for i, t := range targets {
dps[i] = deployingProgress{
DeployingProgress: &protos.DeployingProgress{
Hostname: t.Hostname,
Name: d.Name,
Version: d.Version,
State: "prepare",
},
Timestamp: now,
}
t.opChan <- &opdef{
operation: shared.Deploy,
args: d,
}
}
os.db.Lock()
defer os.db.Unlock()
os.db.progs = dps
}
func (os *operationServer) Withdraw(d WithdrawRequest) {
@ -418,7 +441,7 @@ func (os *operationServer) Hosts() map[string]hostSnapshot {
return os.hp.allHosts()
}
func (os *operationServer) DeplyingProgress() []*protos.DeployingProgress {
func (os *operationServer) DeplyingProgress() []deployingProgress {
return os.db.clone()
}

View File

@ -108,7 +108,7 @@ type Operation interface {
RestartProcess(RestartProcessRequest)
Upload(UploadRequest)
Hosts() map[string]hostSnapshot
DeplyingProgress() []*protos.DeployingProgress
DeplyingProgress() []deployingProgress
}
func loadServerConfig() serverConfig {