Skip to content

Commit

Permalink
feat(fal_client): introduce cancel() (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop authored Oct 24, 2024
1 parent 2492e4b commit 0a228d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions projects/fal_client/src/fal_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"run_async",
"submit_async",
"stream_async",
"cancel",
"cancel_async",
"status",
"status_async",
"result",
"result_async",
"encode",
"encode_file",
"encode_image",
Expand All @@ -40,6 +46,7 @@
submit = sync_client.submit
status = sync_client.status
result = sync_client.result
cancel = sync_client.cancel
stream = sync_client.stream
upload = sync_client.upload
upload_file = sync_client.upload_file
Expand All @@ -51,6 +58,7 @@
submit_async = async_client.submit
status_async = async_client.status
result_async = async_client.result
cancel_async = async_client.cancel
stream_async = async_client.stream
upload_async = async_client.upload
upload_file_async = async_client.upload_file
Expand Down
18 changes: 18 additions & 0 deletions projects/fal_client/src/fal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ def get(self) -> AnyJSON:
_raise_for_status(response)
return response.json()

def cancel(self) -> None:
"""Cancel the request."""
response = self.client.put(self.cancel_url)
_raise_for_status(response)


@dataclass(frozen=True)
class AsyncRequestHandle(_BaseRequestHandle):
Expand Down Expand Up @@ -347,6 +352,11 @@ async def get(self) -> AnyJSON:
_raise_for_status(response)
return response.json()

async def cancel(self) -> None:
"""Cancel the request."""
response = await self.client.put(self.cancel_url)
_raise_for_status(response)


@dataclass(frozen=True)
class AsyncClient:
Expand Down Expand Up @@ -499,6 +509,10 @@ async def result(self, application: str, request_id: str) -> AnyJSON:
handle = self.get_handle(application, request_id)
return await handle.get()

async def cancel(self, application: str, request_id: str) -> None:
handle = self.get_handle(application, request_id)
await handle.cancel()

async def stream(
self,
application: str,
Expand Down Expand Up @@ -721,6 +735,10 @@ def result(self, application: str, request_id: str) -> AnyJSON:
handle = self.get_handle(application, request_id)
return handle.get()

def cancel(self, application: str, request_id: str) -> None:
handle = self.get_handle(application, request_id)
handle.cancel()

def stream(
self,
application: str,
Expand Down

0 comments on commit 0a228d8

Please sign in to comment.