8000 feat: add CLI extra options to ASGI by Sehat1137 · Pull Request #2231 · ag2ai/faststream · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add CLI extra options to ASGI #2231

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Sehat1137
Copy link
Contributor
@Sehat1137 Sehat1137 commented May 25, 2025

Description

faststream run main:app --test 1 --port 5000
from faststream import FastStream, ContextRepo
from faststream.nats import NatsBroker
from faststream.asgi import make_ping_asgi, AsgiResponse, get

broker = NatsBroker()

@get
async def liveness_ping(scope):
    return AsgiResponse(b"", status_code=200)


app = FastStream(broker).as_asgi(
    asgi_routes=[
        ("/liveness", liveness_ping),
        ("/readiness", make_ping_asgi(broker, timeout=5.0)),
    ],
    asyncapi_path="/docs",
)

@app.on_startup
async def start(test: int, port: int):
    print("context.test: ", test)  # 1
    print("context.port: ", port)  # 5000

Type of change

Please delete options that are not relevant.

  • Documentation (typos, code examples, or any documentation updates)
  • Bug fix (a non-breaking change that resolves an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a fix or feature that would disrupt existing functionality)
  • This change requires a documentation update

Checklist

  • My code adheres to the style guidelines of this project (scripts/lint.sh shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • Both new and existing unit tests pass successfully on my local environment by running scripts/test-cov.sh
  • I have ensured that static analysis tests are passing by running scripts/static-analysis.sh
  • I have included code examples to illustrate the modifications

Copy link
Collaborator
@Lancetnik Lancetnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a any kind of test for this userflow? Uvicorn multiprocessing run is the thing we broke last time

import uvicorn
except ImportError:
uvicorn = None
HAS_UVICORN = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should move this constant to _compat to not duplicate uvicorn installation

@@ -134,6 +134,9 @@ class SubscriberNotFound(FastStreamException):
pip install watchfiles
"""

INSTALL_UVICORN = """
You need uvicorn to run FastStream ASGI App via CLI. pip install uvicorn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, change this text in according to other installation notes

except ImportError:
uvicorn = None
UvicornMultiprocess = None
HAS_UVICORN = False
8000 Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should reuse this variable from _compat as well

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.

2 participants
0