Dedup subcommand calls for readiness check

This commit is contained in:
Alex Mirski-Fitton
2022-11-15 15:09:16 +00:00
parent 537320a32d
commit 8efaa55c4f
4 changed files with 47 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
/*
© Copyright IBM Corporation 2017, 2022
© Copyright IBM Corporation 2017, 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -44,7 +44,12 @@ func doMain() int {
}
// Check if the queue manager has a running listener
if active, _ := ready.IsRunningAsActiveQM(ctx, name); active {
status, err := ready.Status(ctx, name)
if err != nil {
return 1
}
switch status {
case ready.StatusActiveQM:
conn, err := net.Dial("tcp", "127.0.0.1:1414")
if err != nil {
fmt.Println(err)
@@ -54,16 +59,16 @@ func doMain() int {
if err != nil {
fmt.Println(err)
}
} else if standby, _ := ready.IsRunningAsStandbyQM(ctx, name); standby {
return 0
case ready.StatusStandbyQM:
fmt.Printf("Detected queue manager running in standby mode")
return 10
} else if replica, _ := ready.IsRunningAsReplicaQM(ctx, name); replica {
case ready.StatusReplicaQM:
fmt.Printf("Detected queue manager running in replica mode")
return 20
} else {
default:
return 1
}
return 0
}
func main() {

View File

@@ -164,11 +164,12 @@ func startQueueManager(name string) error {
func stopQueueManager(name string) error {
log.Println("Stopping queue manager")
qmGracePeriod := os.Getenv("MQ_GRACE_PERIOD")
isStandby, err := ready.IsRunningAsStandbyQM(context.Background(), name)
status, err := ready.Status(context.Background(), name)
if err != nil {
log.Printf("Error getting status for queue manager %v: %v", name, err.Error())
return err
}
isStandby := status.StandbyQM()
args := []string{"-w", "-r", "-tp", qmGracePeriod, name}
if os.Getenv("MQ_MULTI_INSTANCE") == "true" {
if isStandby {