Skip to content

Commit

Permalink
Ensure hooks are triggering in priority order
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Jun 1, 2020
1 parent 980f5af commit bb7d26b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update mylife.py for website changes
- Fixed handling of colons in core IRC parser
- Fix FML random URL
- Ensure hooks are triggered according to priority
### Removed
- twitch.py removed due to outdated API and lack of maintainer
- Remove unused run_before events/tasks
Expand Down
10 changes: 7 additions & 3 deletions cloudbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ def add_hook(hook, _event):
if hook.clients and _event.conn.type not in hook.clients:
return True

coro = self.plugin_manager.launch(hook, _event)
tasks.append(coro)
tasks.append((hook, _event))

if hook.action is Action.HALTALL:
halted = True
Expand Down Expand Up @@ -396,5 +395,10 @@ def add_hook(hook, _event):
# The hook has an action of Action.HALT* so stop adding new tasks
break

tasks.sort(key=lambda t: t[0].priority)

# Run the tasks
await asyncio.gather(*tasks, loop=self.loop)
await asyncio.gather(*[
asyncio.ensure_future(self.plugin_manager.launch(hook, _event))
for hook, _event in tasks
], loop=self.loop)

0 comments on commit bb7d26b

Please sign in to comment.