From 22148f8ae77bd162a09ec9215eade4cc504f40bf Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 26 Oct 2023 13:53:36 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A7=88=EC=A7=80=EB=A7=89=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=83=81=ED=83=9C=20=ED=95=AD=EC=83=81=20=EC=9C=A0?= =?UTF-8?q?=EC=A7=80=20+=20timestamp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 27 ++++++++++++++++--------- server/operation.go | 49 +++++++++++++++++++++++++++++++++------------ server/server.go | 2 +- 3 files changed, 55 insertions(+), 23 deletions(-) diff --git a/client/client.go b/client/client.go index 6909694..8e2f593 100644 --- a/client/client.go +++ b/client/client.go @@ -371,18 +371,27 @@ func NewClient(standalone bool) (HoustonClient, error) { prog := gatherDeployedPrograms(hc.config.StorageRoot, dr.Name) hc.deploys[dr.Name] = prog op.Refresh(ctx, hc.makeOperationQueryRequest()) + + op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ + Hostname: hn, + Name: dr.Name, + Version: dr.Version, + State: "success", + Progress: 0, + Total: 0, + }) } else { logger.Println(err) - } - op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ - Hostname: hn, - Name: dr.Name, - Version: dr.Version, - State: "done", - Progress: 0, - Total: 0, - }) + op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ + Hostname: hn, + Name: dr.Name, + Version: dr.Version, + State: "fail:" + err.Error(), + Progress: 0, + Total: 0, + }) + } } case shared.Withdraw: diff --git a/server/operation.go b/server/operation.go index b19b29f..77c1944 100644 --- a/server/operation.go +++ b/server/operation.go @@ -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() } diff --git a/server/server.go b/server/server.go index b10fc84..d919ca7 100644 --- a/server/server.go +++ b/server/server.go @@ -108,7 +108,7 @@ type Operation interface { RestartProcess(RestartProcessRequest) Upload(UploadRequest) Hosts() map[string]hostSnapshot - DeplyingProgress() []*protos.DeployingProgress + DeplyingProgress() []deployingProgress } func loadServerConfig() serverConfig {