Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Jun 17, 2024
1 parent 0c186a3 commit 6799ab3
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 9 deletions.
7 changes: 5 additions & 2 deletions examples/auto_retry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import dispatch
import dispatch.integrations.requests
import random

import requests

import dispatch
import dispatch.integrations.requests

rng = random.Random(2)


def third_party_api_call(x: int) -> str:
# Simulate a third-party API call that fails.
print(f"Simulating third-party API call with {x}")
Expand Down
5 changes: 4 additions & 1 deletion examples/fanout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import dispatch
import httpx

import dispatch


@dispatch.function
def get_repo(repo_owner: str, repo_name: str):
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}"
Expand Down Expand Up @@ -39,4 +41,5 @@ async def fanout():
)
return await reduce_stargazers(repos)


print(dispatch.run(fanout()))
3 changes: 2 additions & 1 deletion examples/getting_started.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dispatch
import requests

import dispatch


# Use the `dispatch.function` decorator declare a stateful function.
@dispatch.function
Expand Down
4 changes: 3 additions & 1 deletion examples/github_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"""

import dispatch
import httpx

import dispatch
from dispatch.error import ThrottleError


def get_gh_api(url):
print(f"GET {url}")
response = httpx.get(url)
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def set_default_registry(reg: Registry):
# for results.
_calls: Dict[str, asyncio.Future] = {}


class Client:
"""Client for the Dispatch API."""

Expand Down
8 changes: 5 additions & 3 deletions src/dispatch/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
overload,
)

from aiohttp import web, ClientConnectionError
from aiohttp import ClientConnectionError, web
from http_message_signatures import InvalidSignature
from typing_extensions import ParamSpec, TypeAlias

from dispatch.function import Batch, Function, Registry, default_registry, _calls
from dispatch.function import Batch, Function, Registry, _calls, default_registry
from dispatch.proto import CallResult, Input
from dispatch.sdk.v1 import function_pb2 as function_pb
from dispatch.signature import (
Expand Down Expand Up @@ -81,7 +81,9 @@ def function(self, func):
def batch(self) -> Batch:
return self.registry.batch()

async def run(self, url: str, method: str, headers: Mapping[str, str], data: bytes) -> bytes:
async def run(
self, url: str, method: str, headers: Mapping[str, str], data: bytes
) -> bytes:
return await function_service_run(
url,
method,
Expand Down
4 changes: 3 additions & 1 deletion src/dispatch/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ async def _run(self, input: Input) -> Output:
state.suspended = {}


async def run_coroutine(state: State, coroutine: Coroutine, pending_calls: List[Call]) -> Optional[Output]:
async def run_coroutine(
state: State, coroutine: Coroutine, pending_calls: List[Call]
) -> Optional[Output]:
return await make_coroutine(state, coroutine, pending_calls)


Expand Down
1 change: 1 addition & 0 deletions src/dispatch/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def temporary(self) -> bool:
Status.HTTP_ERROR,
}


# Maybe we should find a better way to define that enum. It's that way to please
# Mypy and provide documentation for the enum values.

Expand Down
2 changes: 2 additions & 0 deletions src/dispatch/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

_dispatch_ids = (str(i) for i in range(2**32 - 1))


class Client(BaseClient):
def session(self) -> aiohttp.ClientSession:
# Use an individual sessionn in the test client instead of the default
Expand All @@ -76,6 +77,7 @@ def __init__(self, app: web.Application):
def url(self):
return f"http://{self.host}:{self.port}"


class Service(web.Application):
tasks: Dict[str, asyncio.Task]
_session: Optional[aiohttp.ClientSession] = None
Expand Down

0 comments on commit 6799ab3

Please sign in to comment.