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