Skip to content
Open
24 changes: 22 additions & 2 deletions aiojobs/_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Optional,
Set,
Type,
TypedDict,
TypeVar,
Union,
)
Expand All @@ -24,9 +25,26 @@

Self = TypeVar("Self", bound="Scheduler")


class ExceptionHandlerDict(TypedDict, total=False):
message: str
job: Job
exception: Exception
source_traceback: TracebackType


# * *message*: error message, :class:`str`
# * *job*: failed job, :class:`Job` instance
# * *exception*: caught exception, :exc:`Exception` instance
# * *source_traceback*: a traceback at the moment of job creation
# (present only for debug event loops, see also
# :envvar:`PYTHONASYNCIODEBUG`).

Comment thread
Vizonex marked this conversation as resolved.
Outdated
_T = TypeVar("_T")
_FutureLike = Union["asyncio.Future[_T]", Awaitable[_T]]
ExceptionHandler = Callable[["Scheduler", Dict[str, Any]], None]
ExceptionHandler = Callable[
["Scheduler", Union[ExceptionHandlerDict, Dict[str, Any]]], None
Comment thread
Vizonex marked this conversation as resolved.
Outdated
]


class Scheduler(Collection[Job[object]]):
Expand Down Expand Up @@ -225,7 +243,9 @@ async def close(self) -> None:
self._failed_tasks.put_nowait(None)
await self._failed_task

def call_exception_handler(self, context: Dict[str, Any]) -> None:
def call_exception_handler(
self, context: Union[ExceptionHandlerDict, Dict[str, Any]]
Comment thread
Vizonex marked this conversation as resolved.
Outdated
) -> None:
if self._exception_handler is None:
asyncio.get_running_loop().call_exception_handler(context)
else:
Expand Down
Loading