2018-09-19 15:46:15 +02:00
|
|
|
package reach
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
eventIsReceiverUpgradeAvailable = "is receiver upgrade available"
|
|
|
|
eventReceiverUpgradeAvailable = "receiver upgrade available"
|
|
|
|
)
|
|
|
|
|
|
|
|
type receiverUpgreAvailable struct {
|
|
|
|
Available bool `json:"available"`
|
|
|
|
Running bool `json:"running"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReceiverUpgradeAvailable checks if an upgrade is avaialable/running for the ReachRS module
|
2018-09-19 17:13:45 +02:00
|
|
|
func (u *Updater) ReceiverUpgradeAvailable() (available bool, running bool, err error) {
|
2018-09-19 15:46:15 +02:00
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
err = u.conn.On(eventReceiverUpgradeAvailable, func(h *gosocketio.Channel, up *receiverUpgreAvailable) {
|
2018-09-19 15:46:15 +02:00
|
|
|
available = up.Available
|
|
|
|
running = up.Running
|
2018-09-19 17:13:45 +02:00
|
|
|
u.conn.Off(eventReceiverUpgradeAvailable)
|
2018-09-19 15:46:15 +02:00
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, false, errors.Wrapf(err, "error while binding to '%s' event", eventReceiverUpgradeAvailable)
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
u.logf("sending '%s' event", eventIsReceiverUpgradeAvailable)
|
|
|
|
if err = u.conn.Emit(eventIsReceiverUpgradeAvailable, nil); err != nil {
|
2018-09-19 15:46:15 +02:00
|
|
|
return false, false, errors.Wrapf(err, "error while emitting '%s' event", eventIsReceiverUpgradeAvailable)
|
|
|
|
}
|
2018-09-19 17:13:45 +02:00
|
|
|
u.logf("'%s' event sent", eventIsReceiverUpgradeAvailable)
|
2018-09-19 15:46:15 +02:00
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
u.logf("receiver upgrade result: available: %v, running: %v", available, running)
|
2018-09-19 15:54:11 +02:00
|
|
|
|
2018-09-19 15:46:15 +02:00
|
|
|
return available, running, err
|
|
|
|
|
|
|
|
}
|