mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 16:20:02 +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 {
|
func updateConfigCron() string {
|
||||||
minute := rand.Intn(60) //nolint:gomnd,gosec // Only used to distribute load
|
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() {
|
func updateConfigFromRemote() {
|
||||||
|
log.Debug("starting remote rule update")
|
||||||
err := patchConfig(
|
err := patchConfig(
|
||||||
cfg.Config,
|
cfg.Config,
|
||||||
"Remote Update", "twitch-bot@luzifer.io",
|
"Remote Update", "twitch-bot@luzifer.io",
|
||||||
"update rules from subscription URLs",
|
"update rules from subscription URLs",
|
||||||
func(cfg *configFile) error {
|
func(cfg *configFile) error {
|
||||||
var hasUpdate bool
|
var updates int
|
||||||
|
|
||||||
for _, r := range cfg.Rules {
|
for _, r := range cfg.Rules {
|
||||||
logger := log.WithField("rule", r.MatcherID())
|
logger := log.WithField("rule", r.MatcherID())
|
||||||
|
@ -30,13 +31,13 @@ func updateConfigFromRemote() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if rhu {
|
if rhu {
|
||||||
hasUpdate = true
|
updates++
|
||||||
logger.Info("updated rule from remote URL")
|
logger.Info("updated rule from remote URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasUpdate {
|
log.WithField("updates", updates).Debug("remote rule update finished")
|
||||||
|
if updates == 0 {
|
||||||
return errSaveNotRequired
|
return errSaveNotRequired
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
4
main.go
4
main.go
|
@ -274,7 +274,9 @@ func main() {
|
||||||
|
|
||||||
// Allow config to subscribe to external rules
|
// Allow config to subscribe to external rules
|
||||||
updCron := updateConfigCron()
|
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")
|
log.WithField("cron", updCron).Debug("Initialized remote update cron")
|
||||||
|
|
||||||
router.Use(corsMiddleware)
|
router.Use(corsMiddleware)
|
||||||
|
|
Loading…
Reference in a new issue