Skip to content

Commit 42a69d7

Browse files
authored
Merge pull request #9 from leagueutils/fix/no-error-handling-on-stop
Fix/no error handling on stop
2 parents ded66d6 + 4a9ba69 commit 42a69d7

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
This page contains a fairly detailed, fairly complete, fairly readable summary of what changed with each version of the
44
library.
55

6+
## v1.1.1
7+
Fixed a behaviour where if a trigger with `iter_args` was stopped by raising `triggers.StopRunning()`, the error handler
8+
would be invoked.
9+
610
## v1.1.0
711
This release adds:
812
- an execution limit for triggers. By specifying the `max_trigger_count` parameter, a trigger can be instructed to

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ aren't already running.
7474

7575
If you want to conditionally stop the trigger based on something that happens in the decorated function, you can
7676
simply raise `triggers.StopRunning()` from the function. The trigger will catch that exception, finish processing the
77-
current iteration of the run and exit gracefully after.
77+
current iteration of the run and exit gracefully after. If you want to stop the trigger after executing a fixed
78+
number of times, supply the `max_trigger_count` argument during trigger initialization. The trigger will automatically
79+
and gracefully exit after performing the desired number of executions.
7880

7981
### Error Handling
8082

@@ -83,7 +85,7 @@ The library offers two ways to deal with error handling:
8385
- passing a handler function directly to the trigger's `error_handler` parameter. This allows you to specify
8486
individual error handlers for each repeated task if you need to.
8587
- designating a global error handler by decorating a function with `on_error()`. This will be used
86-
as a fallback by all triggers that don't have a dedicated error handler passed to them during initialisation.
88+
as a fallback by all triggers that don't have a dedicated error handler passed to them during initialization.
8789

8890
An error handler function must be defined with `async def` and accept three parameters in the following order:
8991

@@ -112,7 +114,7 @@ trigger has been called that amount of times, it will exit. If the parameter is
112114
indefinitely.
113115

114116
Triggers allow you to specify a list of elements you want the decorated function to be spread over. If you specify
115-
the `iter_args` parameter when initialising a trigger, it will call the decorated function once for each element of
117+
the `iter_args` parameter when initializing a trigger, it will call the decorated function once for each element of
116118
that parameter. Each element will be positionally passed into the function's first argument. If you prefer to keep
117119
your logic inside the function or load it from somewhere else, simply don't pass the `iter_args` parameter. That will
118120
let the trigger know not to inject any positional args.
@@ -145,7 +147,7 @@ both the decorator variant and the programmatic application of triggers.
145147
### Extending this Library
146148

147149
If you find yourself in need of scheduling logic that none of the included triggers can provide, you can easily
148-
create a trigger class that fits your needs by importing the `BaseTrigger` from this extension, creating a
150+
create a trigger class that fits your needs by importing the `BaseTrigger` from this library, creating a
149151
subclass and overwriting the `next_run` property. The property needs to return a *timezone-aware*
150152
`datetime.datetime` object indicating when the trigger should run next based on the current system time. If you
151153
want to tell the trigger to stop repeating the decorated function and terminate, you can raise `triggers.StopRunning()`

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "triggers"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
description = ""
55
authors = ["lukasthaler <[email protected]>"]
66
readme = "README.md"

triggers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""A library that provides decorators to facilitate automated, periodic repetition of functions."""
22

3-
__version__ = '1.1.0'
3+
__version__ = '1.1.1'
44

55
import types
66

triggers/triggers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def inner():
128128
for arg, res in zip(self.iter_args, results):
129129
if isinstance(res, StopRunning):
130130
terminate = True
131-
if isinstance(res, Exception):
131+
elif isinstance(res, Exception):
132132
await self.__handle_exception(func, arg, res)
133133
if terminate:
134134
raise StopRunning()

0 commit comments

Comments
 (0)