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

Make Task.serve sync compatible #14184

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/prefect/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
)
from prefect.states import Pending, Scheduled, State
from prefect.utilities.annotations import NotSet
from prefect.utilities.asyncutils import run_coro_as_sync
from prefect.utilities.asyncutils import (
run_coro_as_sync,
sync_compatible,
)
from prefect.utilities.callables import (
expand_mapping_parameters,
get_call_parameters,
Expand Down Expand Up @@ -1284,7 +1287,8 @@ def delay(self, *args: P.args, **kwargs: P.kwargs) -> PrefectDistributedFuture:
"""
return self.apply_async(args=args, kwargs=kwargs)

def serve(self) -> "Task":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the return type hint here as nothing is returned by this function or the serve function it calls.

@sync_compatible
async def serve(self):
bunchesofdonald marked this conversation as resolved.
Show resolved Hide resolved
"""Serve the task using the provided task runner. This method is used to
establish a websocket connection with the Prefect server and listen for
submitted task runs to execute.
Expand All @@ -1303,7 +1307,7 @@ def serve(self) -> "Task":
"""
from prefect.task_worker import serve

serve(self)
await serve(self)


@overload
Expand Down