Define web.Application.on_startup() signal handler#1103
Merged
asvetlov merged 1 commit intoaio-libs:masterfrom Aug 22, 2016
Merged
Define web.Application.on_startup() signal handler#1103asvetlov merged 1 commit intoaio-libs:masterfrom
web.Application.on_startup() signal handler#1103asvetlov merged 1 commit intoaio-libs:masterfrom
Conversation
Current coverage is 97.63% (diff: 100%)@@ master #1103 diff @@
==========================================
Files 28 28
Lines 6401 6380 -21
Methods 0 0
Messages 0 0
Branches 1078 1074 -4
==========================================
+ Hits 6159 6229 +70
+ Misses 166 83 -83
+ Partials 76 68 -8
|
e06fc3c to
9302e7e
Compare
Changes:
- Define `web.Application.on_startup()` signal handler.
- Run `app.on_startup()` along with the request handler within an event
loop in `web.run_app()`.
- Tests for `Application.on_startup` signal
- Tests for multiple tasks to run on startup, including two long running
- Extend tests on `web.run_app()`: ensure that `Application.startup()`
is called within `web.run_app()`.
- Add documentation for `Application.on_startup` signal handler:
- Describe possible use cases
- Minor: fix typo
Notes:
In the `tests/test_run_app.py` increased delay for `loop.call_later` from
`0.01s` to `0.02s` since with the old value loop used to stop
before coroutines gathered for `on_startup` finished, that caused
an exception.
9302e7e to
c279825
Compare
Member
|
Thanks you very much! |
Contributor
Author
|
Thank you for your help! :) |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What do these changes do?
This change introduces new signal
Application.on_startup()that allows to register as many
on_startupsignal handlers as needed to run in the event loop along with the application's request handler just after the application's startup.This is useful to run background tasks such as listening to different event sources (message queues, etc.) to process within an application (e.g. to forward to clients connected via WebSocket).
Are there changes in behavior for the user?
The change doesn't impact on existing behavior but extends the API and the functionality.
Related issue number
#1092
Checklist
Changes done
web.Application.on_startup()signal handler.app.on_startup()along with the request handler within an eventloop in
web.run_app().Application.on_startupsignalweb.run_app(): ensure thatApplication.startup()is called within
web.run_app().Application.on_startupsignal handler:Notes
In the
tests/test_run_app.pyincreased delay forloop.call_laterfrom0.01sto0.02ssince with the old value loop used to stopbefore coroutines gathered for
on_startupfinished, that causedan exception.
As discussed earlier, the appropriate changes in the
aiohttp.worker.GunicornWebWorkerwill be applied in a separate PR.