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

Batch submit #127

Merged
merged 4 commits into from
Mar 18, 2024
Merged

Batch submit #127

merged 4 commits into from
Mar 18, 2024

Conversation

chriso
Copy link
Contributor

@chriso chriso commented Mar 17, 2024

Users can dispatch a set of calls using the low-level Client:

class Client:
  def dispatch(calls: Iterable[Call]) -> list[DispatchID])

We construct a Client instance when users use the FastAPI integration, but we don't currently export the client instance.

We provide sugar for dispatching a single call like so:

@dispatch.function
def foo(bar: int): ...

foo.dispatch(1)  # sugar for: client.dispatch([foo.build_call(1)])

We don't provide any sugar for dispatching more than one call to a single function, or to many functions in the same batch.

This PR fixes the issue by providing a way to build and dispatch a batch of calls:

batch = dispatch.batch()

batch.add(func1, *args, **kwargs)
batch.add(func2, *args, **kwargs)
batch.add(func3, *args, **kwargs)
         
batch.dispatch()

Care has been taken to ensure that mypy will check that the types of args/kwargs match the specified function.

@chriso chriso self-assigned this Mar 17, 2024
Copy link
Contributor

@Pryz Pryz left a comment

Choose a reason for hiding this comment

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

🚀

@chriso chriso merged commit 8aa6795 into main Mar 18, 2024
3 checks passed
@chriso chriso deleted the batch-submit branch March 18, 2024 01:14
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