Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define web.Application.on_startup() signal handler #1103

Merged
merged 1 commit into from
Aug 22, 2016

Conversation

f0t0n
Copy link
Contributor

@f0t0n f0t0n commented Aug 22, 2016

What do these changes do?

This change introduces new signal Application.on_startup()
that allows to register as many on_startup signal 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

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

Changes done

  • 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.

As discussed earlier, the appropriate changes in the aiohttp.worker.GunicornWebWorker will be applied in a separate PR.

@codecov-io
Copy link

codecov-io commented Aug 22, 2016

Current coverage is 97.63% (diff: 100%)

Merging #1103 into master will increase coverage by 1.41%

@@             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   

Powered by Codecov. Last update 3c36031...7da1d9f

@f0t0n f0t0n force-pushed the feature/application-on-startup branch 6 times, most recently from e06fc3c to 9302e7e Compare August 22, 2016 16:47
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.
@f0t0n f0t0n force-pushed the feature/application-on-startup branch from 9302e7e to c279825 Compare August 22, 2016 16:54
@asvetlov asvetlov merged commit 41ae0a3 into aio-libs:master Aug 22, 2016
@asvetlov
Copy link
Member

Thanks you very much!

@f0t0n
Copy link
Contributor Author

f0t0n commented Aug 22, 2016

Thank you for your help! :)

@f0t0n f0t0n deleted the feature/application-on-startup branch August 22, 2016 18:02
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants