Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions client/rabbitmq_client.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One important note: errors.Join(...) returns nil in 2 cases:

  1. when no arguments provided like: errors.Join(emptySlice...)
  2. all arguments (=errors) are nil: errors.Join(nilErrorVar, someNilErrorVar)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second case is what we have here

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

amqp "github.com/rabbitmq/amqp091-go"

"errors"
"github.com/babylonlabs-io/staking-queue-client/config"
)

Expand Down Expand Up @@ -262,16 +263,13 @@ func (c *RabbitMqClient) SendMessage(ctx context.Context, messageBody string) er

// Stop stops the message receiving process.
func (c *RabbitMqClient) Stop() error {
if err := c.channel.Close(); err != nil {
return err
}
if err := c.connection.Close(); err != nil {
return err
}
var channelErr, connectionErr error

channelErr = c.channel.Close()
connectionErr = c.connection.Close()
close(c.stopCh)

return nil
return errors.Join(channelErr, connectionErr)
}

func (c *RabbitMqClient) GetQueueName() string {
Expand Down
12 changes: 5 additions & 7 deletions queuemngr/queue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"go.uber.org/zap"

"errors"
"github.com/babylonlabs-io/staking-queue-client/client"
"github.com/babylonlabs-io/staking-queue-client/config"
)
Expand Down Expand Up @@ -94,15 +95,12 @@ func (qc *QueueManager) ReQueueMessage(ctx context.Context, message client.Queue
}

func (qc *QueueManager) Stop() error {
if err := qc.ActiveStakingQueue.Stop(); err != nil {
return err
}
var activeErr, unbondingErr error

if err := qc.UnbondingStakingQueue.Stop(); err != nil {
return err
}
activeErr = qc.ActiveStakingQueue.Stop()
unbondingErr = qc.UnbondingStakingQueue.Stop()

return nil
return errors.Join(activeErr, unbondingErr)
}

// Ping checks the health of the RabbitMQ infrastructure.
Expand Down