twitch-bot/internal/apimodules/customevent/scheduler.go

37 lines
787 B
Go
Raw Permalink Normal View History

package customevent
import (
"strings"
"github.com/sirupsen/logrus"
)
func scheduleCleanup() {
if err := cleanupStoredEvents(db); err != nil {
logrus.WithError(err).Error("executing custom event database cleanup")
}
}
func scheduleSend() {
evts, err := mc.PopEventsToExecute()
if err != nil {
logrus.WithError(err).Error("collecting scheduled custom events for sending")
return
}
for i := range evts {
go func(evt storedCustomEvent) {
evtData, err := parseEvent(evt.Channel, strings.NewReader(evt.Fields))
if err != nil {
logrus.WithError(err).Error("parsing fields in stored event")
return
}
if err = eventCreatorFunc("custom", evtData); err != nil {
logrus.WithError(err).Error("triggering stored event")
return
}
}(evts[i])
}
}