mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
[core] Fix: Remote-update cron broken as of missing field
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
9ec1117490
commit
f870042195
2 changed files with 9 additions and 6 deletions
|
@ -9,16 +9,17 @@ import (
|
|||
|
||||
func updateConfigCron() string {
|
||||
minute := rand.Intn(60) //nolint:gomnd,gosec // Only used to distribute load
|
||||
return fmt.Sprintf("%d * * * *", minute)
|
||||
return fmt.Sprintf("0 %d * * * *", minute)
|
||||
}
|
||||
|
||||
func updateConfigFromRemote() {
|
||||
log.Debug("starting remote rule update")
|
||||
err := patchConfig(
|
||||
cfg.Config,
|
||||
"Remote Update", "twitch-bot@luzifer.io",
|
||||
"update rules from subscription URLs",
|
||||
func(cfg *configFile) error {
|
||||
var hasUpdate bool
|
||||
var updates int
|
||||
|
||||
for _, r := range cfg.Rules {
|
||||
logger := log.WithField("rule", r.MatcherID())
|
||||
|
@ -30,13 +31,13 @@ func updateConfigFromRemote() {
|
|||
}
|
||||
|
||||
if rhu {
|
||||
hasUpdate = true
|
||||
updates++
|
||||
logger.Info("updated rule from remote URL")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if !hasUpdate {
|
||||
log.WithField("updates", updates).Debug("remote rule update finished")
|
||||
if updates == 0 {
|
||||
return errSaveNotRequired
|
||||
}
|
||||
return nil
|
||||
|
|
4
main.go
4
main.go
|
@ -274,7 +274,9 @@ func main() {
|
|||
|
||||
// Allow config to subscribe to external rules
|
||||
updCron := updateConfigCron()
|
||||
cronService.AddFunc(updCron, updateConfigFromRemote)
|
||||
if _, err = cronService.AddFunc(updCron, updateConfigFromRemote); err != nil {
|
||||
log.WithError(err).Error("adding remote-update cron")
|
||||
}
|
||||
log.WithField("cron", updCron).Debug("Initialized remote update cron")
|
||||
|
||||
router.Use(corsMiddleware)
|
||||
|
|
Loading…
Reference in a new issue