Skip to content

Commit

Permalink
Add handlers for nil
Browse files Browse the repository at this point in the history
Add handlers for the rare case that the connection is nil.
  • Loading branch information
grisu48 committed Oct 2, 2023
1 parent 03af6e1 commit 1d5b30f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ type RabbitMQCloseCallback func(error)
// Close connection
func (mq *RabbitMQ) Close() {
mq.closed = true
mq.con.Close()
if mq.con != nil {
mq.con.Close()
}
}

// Connected returns true if RabbitMQ is connected
func (mq *RabbitMQ) Connected() bool {
return !mq.closed && !mq.con.IsClosed()
return !mq.closed && (mq.con != nil) && !mq.con.IsClosed()
}

// Connected returns true if RabbitMQ is closing or if it is closed.
func (mq *RabbitMQ) Closed() bool {
if mq.closed {
return true
}
if mq.con.IsClosed() {
if mq.con == nil || mq.con.IsClosed() {
mq.closed = true
return true
}
Expand All @@ -73,7 +75,9 @@ func (mq *RabbitMQ) Closed() bool {
// Reconnect to the RabbitMQ server. This will close any previous connections and channels
func (mq *RabbitMQ) Reconnect() error {
var err error
mq.con.Close()
if mq.con != nil {
mq.con.Close()
}
mq.closed = false
mq.con, err = amqp.Dial(mq.remote)
return err
Expand Down Expand Up @@ -145,6 +149,7 @@ func (sub *RabbitMQSubscription) ReceiveJobStatus() (JobStatus, error) {
return status, err
}

// Required due to poo#114529
type IJobStatus struct {
Type string // Type of the update. Currently "job.done" and "job.restarted" are set
Arch string `json:"ARCH"`
Expand Down

0 comments on commit 1d5b30f

Please sign in to comment.