mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix: irc network distinguish inactive and error (#76)
This commit is contained in:
parent
27f902041b
commit
d8c37dde2f
2 changed files with 48 additions and 17 deletions
|
@ -41,6 +41,12 @@ func (h *channelHealth) SetMonitoring() {
|
|||
h.monitoringSince = time.Now()
|
||||
}
|
||||
|
||||
// resetMonitoring remove monitoring and time
|
||||
func (h *channelHealth) resetMonitoring() {
|
||||
h.monitoring = false
|
||||
h.monitoringSince = time.Time{}
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
network *domain.IrcNetwork
|
||||
filterService filter.Service
|
||||
|
@ -241,17 +247,15 @@ func (s *Handler) Run() error {
|
|||
s.client = client
|
||||
|
||||
// set connected since now
|
||||
s.connectedSince = time.Now()
|
||||
s.connected = true
|
||||
s.setConnectionStatus()
|
||||
|
||||
// Connect
|
||||
err = client.RunContext(ctx)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("could not connect to %v", addr)
|
||||
|
||||
// set connected false if we loose connection or stop
|
||||
s.connectedSince = time.Time{}
|
||||
s.connected = false
|
||||
// reset connection status on handler and channels
|
||||
s.resetConnectionStatus()
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -259,6 +263,25 @@ func (s *Handler) Run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Handler) setConnectionStatus() {
|
||||
// set connected since now
|
||||
s.connectedSince = time.Now()
|
||||
s.connected = true
|
||||
}
|
||||
|
||||
func (s *Handler) resetConnectionStatus() {
|
||||
// set connected false if we loose connection or stop
|
||||
s.connectedSince = time.Time{}
|
||||
s.connected = false
|
||||
|
||||
// loop over channelHealth and reset each one
|
||||
for _, h := range s.channelHealth {
|
||||
if h != nil {
|
||||
h.resetMonitoring()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Handler) GetNetwork() *domain.IrcNetwork {
|
||||
return s.network
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue