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

Add no-op asgi-lifespan handling #1

Merged
merged 1 commit into from
Nov 16, 2022
Merged

Add no-op asgi-lifespan handling #1

merged 1 commit into from
Nov 16, 2022

Conversation

sheenobu
Copy link
Owner

Super simple hook that checks for lifespan and immediately responds type.complete, essentially making startup/shutdown lifespan events no-ops for the prometheus ASGI app.

Fixes prometheus#855

from hypercorn.middleware import DispatcherMiddleware
from prometheus_client import make_asgi_app
import asyncio

async def main():

    from hypercorn.asyncio import serve
    from hypercorn.config import Config

    app = DispatcherMiddleware({
        "/metrics": make_asgi_app(),
    })


    config = Config()
    config.bind = ["localhost:8080"]

    await serve(app, config)

Before:

    assert scope.get("type") == "http"
AssertionError

After:

[2022-11-15 16:05:20 -0800] [59048] [INFO] Running on http://127.0.0.1:8080 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:8080 (CTRL + C to quit)

Signed-off-by: Sheena Artrip [email protected]

Super simple hook that checks for lifespan and immediately responds type.complete, essentially making startup/shutdown lifespan events no-ops for the prometheus ASGI app.

Fixes prometheus#855

```
from hypercorn.middleware import DispatcherMiddleware
from prometheus_client import make_asgi_app
import asyncio

async def main():

    from hypercorn.asyncio import serve
    from hypercorn.config import Config

    app = DispatcherMiddleware({
        "/metrics": make_asgi_app(),
    })


    config = Config()
    config.bind = ["localhost:8080"]

    await serve(app, config)
```

Before:

```
    assert scope.get("type") == "http"
AssertionError
```

After:

```
[2022-11-15 16:05:20 -0800] [59048] [INFO] Running on http://127.0.0.1:8080 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:8080 (CTRL + C to quit)
```

Signed-off-by: Sheena Artrip <[email protected]>
@sheenobu sheenobu merged commit 36acde4 into master Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASGI lifespan crash
1 participant