This commit is contained in:
parent
4a21568bcd
commit
db7012fe3b
@ -13,29 +13,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TickerTime = time.Second
|
tickerTime = time.Second
|
||||||
Timeout = 5 * time.Second
|
timeout = 5 * time.Second
|
||||||
TimeoutWait = time.Second / 2
|
timeoutWait = time.Second / 2
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var errTimeout = errors.New("timeout")
|
||||||
ErrCouldNotConnect = errors.New("could not connect")
|
|
||||||
ErrTimeout = errors.New("timeout")
|
|
||||||
)
|
|
||||||
|
|
||||||
func Conn() (*mpd.Client, error) {
|
func Conn() (*mpd.Client, error) {
|
||||||
t := time.NewTimer(Timeout)
|
t := time.NewTimer(timeout)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
return nil, ErrTimeout
|
return nil, errTimeout
|
||||||
default:
|
default:
|
||||||
c, err := mpd.Dial("tcp", fmt.Sprintf("%s:%d", config.Cfg.MPD.Hostname, config.Cfg.MPD.Port))
|
c, err := mpd.Dial("tcp", fmt.Sprintf("%s:%d", config.Cfg.MPD.Hostname, config.Cfg.MPD.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("could not connect")
|
log.Error().Err(err).Msg("could not connect")
|
||||||
|
|
||||||
time.Sleep(TimeoutWait)
|
time.Sleep(timeoutWait)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -77,7 +74,7 @@ func PlaylistURIS() ([]string, error) {
|
|||||||
func Watcher() {
|
func Watcher() {
|
||||||
log.Debug().Msg("starting watch")
|
log.Debug().Msg("starting watch")
|
||||||
|
|
||||||
ticker := time.NewTicker(TickerTime)
|
ticker := time.NewTicker(tickerTime)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -121,6 +118,7 @@ func Stop(logger zerolog.Logger) error {
|
|||||||
return fmt.Errorf("could not connect: %w", err)
|
return fmt.Errorf("could not connect: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:wrapcheck
|
||||||
return m.Stop()
|
return m.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +130,7 @@ func Clear(logger zerolog.Logger) error {
|
|||||||
return fmt.Errorf("could not connect: %w", err)
|
return fmt.Errorf("could not connect: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:wrapcheck
|
||||||
return m.Clear()
|
return m.Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +163,7 @@ func Play(logger zerolog.Logger, rfid string, name string, uris []string) error
|
|||||||
if err := m.Add(i); err != nil {
|
if err := m.Add(i); err != nil {
|
||||||
metrics.BoxErrors.Inc()
|
metrics.BoxErrors.Inc()
|
||||||
|
|
||||||
return err
|
return fmt.Errorf("could not add track: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,5 +178,6 @@ func Play(logger zerolog.Logger, rfid string, name string, uris []string) error
|
|||||||
|
|
||||||
metrics.NewPlay(rfid, name, mpdURIS)
|
metrics.NewPlay(rfid, name, mpdURIS)
|
||||||
|
|
||||||
|
// nolint:wrapcheck
|
||||||
return m.Play(-1)
|
return m.Play(-1)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//nolint:wrapcheck
|
|
||||||
package run
|
package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
Reference in New Issue
Block a user