rename: ctx, stopCtx

Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
Luca Bigliardi 2021-03-22 16:00:03 +01:00
parent 9c53b88cd9
commit 94ccf2ebd7

18
irc.go
View File

@ -70,7 +70,7 @@ type IRCNotifier struct {
Client *irc.Conn Client *irc.Conn
AlertMsgs chan AlertMsg AlertMsgs chan AlertMsg
ctx context.Context stopCtx context.Context
stopWg *sync.WaitGroup stopWg *sync.WaitGroup
// irc.Conn has a Connected() method that can tell us wether the TCP // irc.Conn has a Connected() method that can tell us wether the TCP
@ -91,7 +91,7 @@ type IRCNotifier struct {
BackoffCounter Delayer BackoffCounter Delayer
} }
func NewIRCNotifier(ctx context.Context, stopWg *sync.WaitGroup, config *Config, alertMsgs chan AlertMsg) (*IRCNotifier, error) { func NewIRCNotifier(stopCtx context.Context, stopWg *sync.WaitGroup, config *Config, alertMsgs chan AlertMsg) (*IRCNotifier, error) {
ircConfig := irc.NewConfig(config.IRCNick) ircConfig := irc.NewConfig(config.IRCNick)
ircConfig.Me.Ident = config.IRCNick ircConfig.Me.Ident = config.IRCNick
@ -117,7 +117,7 @@ func NewIRCNotifier(ctx context.Context, stopWg *sync.WaitGroup, config *Config,
NickPassword: config.IRCNickPass, NickPassword: config.IRCNickPass,
Client: irc.Client(ircConfig), Client: irc.Client(ircConfig),
AlertMsgs: alertMsgs, AlertMsgs: alertMsgs,
ctx: ctx, stopCtx: stopCtx,
stopWg: stopWg, stopWg: stopWg,
sessionUpSignal: make(chan bool), sessionUpSignal: make(chan bool),
sessionDownSignal: make(chan bool), sessionDownSignal: make(chan bool),
@ -164,7 +164,7 @@ func (n *IRCNotifier) HandleKick(nick string, channel string) {
} }
log.Printf("Being kicked out of %s, re-joining", channel) log.Printf("Being kicked out of %s, re-joining", channel)
go func() { go func() {
if ok := state.BackoffCounter.DelayContext(n.ctx); !ok { if ok := state.BackoffCounter.DelayContext(n.stopCtx); !ok {
return return
} }
n.Client.Join(state.Channel.Name, state.Channel.Password) n.Client.Join(state.Channel.Name, state.Channel.Password)
@ -263,7 +263,7 @@ func (n *IRCNotifier) ConnectedPhase() {
n.CleanupChannels() n.CleanupChannels()
n.Client.Quit("see ya") n.Client.Quit("see ya")
ircConnectedGauge.Set(0) ircConnectedGauge.Set(0)
case <-n.ctx.Done(): case <-n.stopCtx.Done():
log.Printf("IRC routine asked to terminate") log.Printf("IRC routine asked to terminate")
} }
} }
@ -271,10 +271,10 @@ func (n *IRCNotifier) ConnectedPhase() {
func (n *IRCNotifier) SetupPhase() { func (n *IRCNotifier) SetupPhase() {
if !n.Client.Connected() { if !n.Client.Connected() {
log.Printf("Connecting to IRC %s", n.Client.Config().Server) log.Printf("Connecting to IRC %s", n.Client.Config().Server)
if ok := n.BackoffCounter.DelayContext(n.ctx); !ok { if ok := n.BackoffCounter.DelayContext(n.stopCtx); !ok {
return return
} }
if err := n.Client.ConnectContext(n.ctx); err != nil { if err := n.Client.ConnectContext(n.stopCtx); err != nil {
log.Printf("Could not connect to IRC: %s", err) log.Printf("Could not connect to IRC: %s", err)
return return
} }
@ -288,7 +288,7 @@ func (n *IRCNotifier) SetupPhase() {
ircConnectedGauge.Set(1) ircConnectedGauge.Set(1)
case <-n.sessionDownSignal: case <-n.sessionDownSignal:
log.Printf("Receiving a session down before the session is up, this is odd") log.Printf("Receiving a session down before the session is up, this is odd")
case <-n.ctx.Done(): case <-n.stopCtx.Done():
log.Printf("IRC routine asked to terminate") log.Printf("IRC routine asked to terminate")
} }
} }
@ -296,7 +296,7 @@ func (n *IRCNotifier) SetupPhase() {
func (n *IRCNotifier) Run() { func (n *IRCNotifier) Run() {
defer n.stopWg.Done() defer n.stopWg.Done()
for n.ctx.Err() != context.Canceled { for n.stopCtx.Err() != context.Canceled {
if !n.sessionUp { if !n.sessionUp {
n.SetupPhase() n.SetupPhase()
} else { } else {