Add signal functionality to manage events (after_token_refresh) #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #46 (and may fix it)
This adds a base functionality to trigger alarms/signals (or whatever the name you give them) in pycrest.
Basically, you have instances of
Signal
, each one represents a specific event. These signals, when triggered (usingSignal.send(**kwargs)
orSignal.send_robust(**kwargs)
if you want to silence exception (still logged using logger)), will call all receivers they registered and give them the same arguments.A receiver is just any callable object you my have (function, class methods, class with
__call__()
).The doc has also been updated to show how to use signals in the code (import signal, add/remove receivers)
Currently the only event added is the
after_token_refresh
signal, fired each timeAuthedConnection.refresh()
is called with these arguments :access_token
refresh_token
expires_in
This a really lightweight inspiration from the django's signal that gives the advantage the "core code" only need to know which events he wants to fire, without dealing with list of receivers, etc.
On a side note, and not directly related to this PR main subject, I splitted the tests, moving cache tests and event tests in their own files (and fixing a few pep issues at the same time)