Dedup subcommand calls for readiness check
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
© Copyright IBM Corporation 2018, 2022
|
||||
© Copyright IBM Corporation 2018, 2023
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -43,8 +43,8 @@ func GatherMetrics(qmName string, log *logger.Logger) {
|
||||
|
||||
// If running in standby mode - wait until the queue manager becomes active
|
||||
for {
|
||||
active, _ := ready.IsRunningAsActiveQM(context.Background(), qmName)
|
||||
if active {
|
||||
status, _ := ready.Status(context.Background(), qmName)
|
||||
if status.ActiveQM() {
|
||||
break
|
||||
}
|
||||
time.Sleep(requestTimeout * time.Second)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
© Copyright IBM Corporation 2018, 2022
|
||||
© Copyright IBM Corporation 2018, 2023
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -67,28 +67,38 @@ func Check() (bool, error) {
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// IsRunningAsActiveQM returns true if the queue manager is running in active mode
|
||||
func IsRunningAsActiveQM(ctx context.Context, name string) (bool, error) {
|
||||
return isRunningQM(ctx, name, "(RUNNING)")
|
||||
}
|
||||
|
||||
// IsRunningAsStandbyQM returns true if the queue manager is running in standby mode
|
||||
func IsRunningAsStandbyQM(ctx context.Context, name string) (bool, error) {
|
||||
return isRunningQM(ctx, name, "(RUNNING AS STANDBY)")
|
||||
}
|
||||
|
||||
// IsRunningAsReplicaQM returns true if the queue manager is running in replica mode
|
||||
func IsRunningAsReplicaQM(ctx context.Context, name string) (bool, error) {
|
||||
return isRunningQM(ctx, name, "(REPLICA)")
|
||||
}
|
||||
|
||||
func isRunningQM(ctx context.Context, name string, status string) (bool, error) {
|
||||
// Status returns an enum representing the current running status of the queue manager
|
||||
func Status(ctx context.Context, name string) (QMStatus, error) {
|
||||
out, _, err := command.RunContext(ctx, "dspmq", "-n", "-m", name)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return StatusUnknown, err
|
||||
}
|
||||
if strings.Contains(string(out), status) {
|
||||
return true, nil
|
||||
if strings.Contains(string(out), "(RUNNING)") {
|
||||
return StatusActiveQM, nil
|
||||
}
|
||||
return false, nil
|
||||
if strings.Contains(string(out), "(RUNNING AS STANDBY)") {
|
||||
return StatusStandbyQM, nil
|
||||
}
|
||||
if strings.Contains(string(out), "(REPLICA)") {
|
||||
return StatusStandbyQM, nil
|
||||
}
|
||||
return StatusUnknown, nil
|
||||
}
|
||||
|
||||
type QMStatus int
|
||||
|
||||
const (
|
||||
StatusUnknown QMStatus = iota
|
||||
StatusActiveQM
|
||||
StatusStandbyQM
|
||||
StatusReplicaQM
|
||||
)
|
||||
|
||||
// ActiveQM returns true if the queue manager is running in active mode
|
||||
func (s QMStatus) ActiveQM() bool { return s == StatusActiveQM }
|
||||
|
||||
// StandbyQM returns true if the queue manager is running in standby mode
|
||||
func (s QMStatus) StandbyQM() bool { return s == StatusStandbyQM }
|
||||
|
||||
// ReplicaQM returns true if the queue manager is running in replica mode
|
||||
func (s QMStatus) ReplicaQM() bool { return s == StatusReplicaQM }
|
||||
|
||||
Reference in New Issue
Block a user