mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
[core] Parallelize rule execution
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ee5e7359a2
commit
a07ad6fe83
1 changed files with 48 additions and 39 deletions
23
actions.go
23
actions.go
|
@ -71,7 +71,13 @@ func handleMessage(c *irc.Client, m *irc.Message, event *string, eventData *plug
|
||||||
go notifyEventHandlers(*event, eventData)
|
go notifyEventHandlers(*event, eventData)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range config.GetMatchingRules(m, event, eventData) {
|
matchingRules := config.GetMatchingRules(m, event, eventData)
|
||||||
|
for i := range matchingRules {
|
||||||
|
go handleMessageRuleExecution(c, m, matchingRules[i], eventData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMessageRuleExecution(c *irc.Client, m *irc.Message, r *plugins.Rule, eventData *plugins.FieldCollection) {
|
||||||
var (
|
var (
|
||||||
ruleEventData = plugins.NewFieldCollection()
|
ruleEventData = plugins.NewFieldCollection()
|
||||||
preventCooldown bool
|
preventCooldown bool
|
||||||
|
@ -88,27 +94,30 @@ func handleMessage(c *irc.Client, m *irc.Message, event *string, eventData *plug
|
||||||
case err == nil:
|
case err == nil:
|
||||||
// Rule execution did not cause an error, we store the
|
// Rule execution did not cause an error, we store the
|
||||||
// cooldown modifier and continue
|
// cooldown modifier and continue
|
||||||
|
|
||||||
preventCooldown = preventCooldown || apc
|
preventCooldown = preventCooldown || apc
|
||||||
continue ActionsLoop
|
continue ActionsLoop
|
||||||
|
|
||||||
case errors.Is(err, plugins.ErrStopRuleExecution):
|
case errors.Is(err, plugins.ErrStopRuleExecution):
|
||||||
// Action has asked to stop executing this rule so we store
|
// Action has asked to stop executing this rule so we store
|
||||||
// the cooldown modifier and stop executing the actions stack
|
// the cooldown modifier and stop executing the actions stack
|
||||||
|
// Action experienced an error: We don't store the cooldown
|
||||||
|
// state of this action and stop executing the actions stack
|
||||||
|
// for this rule
|
||||||
|
|
||||||
preventCooldown = preventCooldown || apc
|
preventCooldown = preventCooldown || apc
|
||||||
break ActionsLoop
|
break ActionsLoop
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Action experienced an error: We don't store the cooldown
|
// Break execution for this rule when one action fails
|
||||||
// state of this action and stop executing the actions stack
|
// Lock command
|
||||||
// for this rule
|
|
||||||
log.WithError(err).Error("Unable to trigger action")
|
log.WithError(err).Error("Unable to trigger action")
|
||||||
break ActionsLoop // Break execution for this rule when one action fails
|
break ActionsLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock command
|
|
||||||
if !preventCooldown {
|
if !preventCooldown {
|
||||||
r.SetCooldown(timerService, m, eventData)
|
r.SetCooldown(timerService, m, eventData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue