Fill out logging TODOs in state package
This change adds logging where requested via TODOs in state.go.
This commit is contained in:
parent
dd2d8aa9b3
commit
6d2375b396
1 changed files with 30 additions and 4 deletions
|
|
@ -8,11 +8,13 @@ package state
|
|||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"gitlab.com/whom/bingobot/internal/logging"
|
||||
)
|
||||
|
||||
/* Event interface is meant to encapsulate a general interface
|
||||
|
|
@ -165,14 +167,29 @@ func PublishEvent(e Event) error {
|
|||
eventMutex.Unlock()
|
||||
eventMutex.RLock()
|
||||
defer eventMutex.RUnlock()
|
||||
|
||||
blocking := false
|
||||
|
||||
for _, c := range eventSubscriptionCache[e.Type()] {
|
||||
if float32(len(c)) > (float32(eventChannelBufferSize) * 0.25) {
|
||||
if len(c) == eventChannelBufferSize {
|
||||
// TODO: log that this publish is blocking
|
||||
// on a full channel
|
||||
logging.Warn(
|
||||
"PublishEvent() blocking -- event channel full",
|
||||
// log the event time to provide blockage timing information
|
||||
// in the logs
|
||||
"eventTime",
|
||||
e.Time(),
|
||||
)
|
||||
blocking = true
|
||||
}
|
||||
}
|
||||
c <- e
|
||||
|
||||
if blocking {
|
||||
logging.Info("PublishEvent() no longer blocking")
|
||||
blocking = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -259,9 +276,13 @@ func (ve VoteEvent) Time() time.Time {
|
|||
t, e := time.Parse(time.RFC3339, ve[VoteCreatedKey])
|
||||
if e != nil {
|
||||
// we have a corrupted event
|
||||
// TODO: log first
|
||||
// return old time so that this event gets
|
||||
// pruned from cache
|
||||
logging.Warn(
|
||||
"pruning corrupted vote event",
|
||||
"event",
|
||||
fmt.Sprintf("%+v", ve),
|
||||
)
|
||||
tooOld, _ := time.Parse(
|
||||
time.RFC3339,
|
||||
VeryOldVote,
|
||||
|
|
@ -343,9 +364,14 @@ func (ue UserEvent) Validate() error {
|
|||
_, err := DiscordSession.User(ue.uid)
|
||||
return err
|
||||
} else {
|
||||
// TODO: Log validation failure
|
||||
// I would love to know how to actually fail here
|
||||
// and still have unit testable code.
|
||||
|
||||
logging.Error(
|
||||
"can't validate UserEvent: nil discord session",
|
||||
"event",
|
||||
fmt.Sprintf("%+v", ue),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue