twitch-bot/internal/apimodules/customevent/scheduler.go
Knut Ahlers ffd6c9bd09
[customevent] Add scheduled custom events
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2022-10-31 15:51:28 +01:00

36 lines
787 B
Go

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])
}
}