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

Dispatch without FastAPI #154

Merged
merged 16 commits into from
Apr 23, 2024
Merged

Dispatch without FastAPI #154

merged 16 commits into from
Apr 23, 2024

Conversation

achille-roussel
Copy link
Contributor

This PR relates to dispatchrun/dispatch#12 and dispatchrun/dispatch#19, and is intended to make FastAPI an optional dependency for Dispatch.

I first went down the path of using the gRPC service as a replacement; however, requiring HTTP/2 made a few things difficult since the CLI will attempt HTTP/1 requests (because the connectrpc protocol allows it); see dispatch.grpc.

Rather than hacking something with fake certs and whatnot, I added another implementation using http.server, which is very similar to the one with FastAPI but integrates with the standard library only; see dispatch.http.

This is still work in progress, I need to add tests.

@achille-roussel achille-roussel added the enhancement New feature or request label Apr 17, 2024
@achille-roussel achille-roussel self-assigned this Apr 17, 2024
@vadimdemedes
Copy link

This will be great for onboarding 👍

@achille-roussel achille-roussel force-pushed the dispatch-without-fastapi branch from 6e14930 to 49da99e Compare April 22, 2024 21:21
Signed-off-by: Achille Roussel <[email protected]>
Signed-off-by: Achille Roussel <[email protected]>
Dockerfile Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
Comment on lines +92 to +98
try:
if init is not None:
init(*args, **kwargs)
server.serve_forever()
finally:
server.shutdown()
server.server_close()
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if you Ctrl+C out of the blocking call? Should we catch KeyboardInterrupt and pass so that an exception isn't raised and stack trace printed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This happens:

$ ./dispatch run -- ./main.py

  ╭───────────────────────────────────────────────────────────────────╮
  │                                                                   │
  │  Starting Dispatch session: ce77804d-b40d-4df7-b8a4-d10afcc4ab31  │
  │                                                                   │
  │  Run 'dispatch help run' to learn about Dispatch sessions.        │
  │                                                                   │
  ╰───────────────────────────────────────────────────────────────────╯

Hello, World!
127.0.0.1 - - [22/Apr/2024 18:22:23] "POST /dispatch.sdk.v1.FunctionService/Run HTTP/1.1" 200 -
^C
  ╭────────────────────────────────────────────────────────────────────────────────╮
  │                                                                                │
  │  To resume this Dispatch session:                                              │
  │                                                                                │
  │      dispatch run --session ce77804d-b40d-4df7-b8a4-d10afcc4ab31 -- ./main.py  │
  │                                                                                │
  ╰────────────────────────────────────────────────────────────────────────────────╯

Copy link
Contributor

@chriso chriso Apr 23, 2024

Choose a reason for hiding this comment

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

Ah right because we send SIGTERM rather than passing on the signal the CLI receives here: https://github.com/stealthrocket/dispatch/blob/00ad5441b8da130d378af1843af364241906b828/cli/run.go#L171. I think I had it passing on the signal originally, but uvicorn was handling SIGINT differently when it was run inside the CLI (and wasn't itself interactive) and it was printing a nasty stack trace.

src/dispatch/grpc.py Outdated Show resolved Hide resolved
src/dispatch/http.py Outdated Show resolved Hide resolved
achille-roussel and others added 4 commits April 22, 2024 18:21
Co-authored-by: Chris O'Hara <[email protected]>
Co-authored-by: Chris O'Hara <[email protected]>
Signed-off-by: Achille Roussel <[email protected]>
Signed-off-by: Achille Roussel <[email protected]>
@achille-roussel achille-roussel merged commit bfdd64b into main Apr 23, 2024
10 checks passed
@achille-roussel achille-roussel deleted the dispatch-without-fastapi branch April 23, 2024 01:43
@Pryz Pryz mentioned this pull request May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants