Add changed files to reload trigger listener

This commit is contained in:
Adam Hopkins 2023-08-23 09:31:27 +03:00
parent 16256522f6
commit f3035abfae
No known key found for this signature in database
GPG Key ID: 9F85EE6C807303FB
2 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,6 @@ from __future__ import annotations
from inspect import isawaitable
from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional
if TYPE_CHECKING:
from sanic import Sanic
@ -12,6 +11,7 @@ def trigger_events(
events: Optional[Iterable[Callable[..., Any]]],
loop,
app: Optional[Sanic] = None,
**kwargs,
):
"""
Trigger event callbacks (functions or async)
@ -22,8 +22,12 @@ def trigger_events(
if events:
for event in events:
try:
result = event() if not app else event(app)
result = event(**kwargs) if not app else event(app, **kwargs)
except TypeError:
result = event(loop) if not app else event(app, loop)
result = (
event(loop, **kwargs)
if not app
else event(app, loop, **kwargs)
)
if isawaitable(result):
loop.run_until_complete(result)

View File

@ -2,7 +2,6 @@ from __future__ import annotations
import os
import sys
from asyncio import new_event_loop
from itertools import chain
from multiprocessing.connection import Connection
@ -64,7 +63,7 @@ class Reloader:
trigger_events(before_trigger, loop, app)
self.reload(",".join(changed) if changed else "unknown")
if after_trigger:
trigger_events(after_trigger, loop, app)
trigger_events(after_trigger, loop, app, changed=changed)
sleep(self.interval)
else:
if reloader_stop: