Skip to content

fix: some minor issues #342

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

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions taskiq/depends/progress_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
from taskiq.compat import IS_PYDANTIC2
from taskiq.context import Context

if IS_PYDANTIC2:
from pydantic import BaseModel as GenericModel
else:
from pydantic.generics import GenericModel # type: ignore[no-redef]


_ProgressType = TypeVar("_ProgressType")


Expand All @@ -25,15 +19,26 @@ class TaskState(str, enum.Enum):
RETRY = "RETRY"


class TaskProgress(GenericModel, Generic[_ProgressType]):
if IS_PYDANTIC2:
from pydantic import BaseModel, ConfigDict

class _TaskProgressConfig(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)

else:
from pydantic.generics import GenericModel

class _TaskProgressConfig(GenericModel): # type: ignore[no-redef]
class Config:
arbitrary_types_allowed = True


class TaskProgress(_TaskProgressConfig, Generic[_ProgressType]):
"""Progress of task execution."""

state: Union[TaskState, str]
meta: Optional[_ProgressType]

class Config:
arbitrary_types_allowed = True


class ProgressTracker(Generic[_ProgressType]):
"""Task's dependency to set progress."""
Expand Down
6 changes: 4 additions & 2 deletions taskiq/receiver/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ def task_cb(task: "asyncio.Task[Any]") -> None:
self.sem_prefetch.release()
message = await queue.get()
if message is QUEUE_DONE:
logger.info("Waiting for running tasks to complete.")
await asyncio.wait(tasks, timeout=self.wait_tasks_timeout)
# asyncio.wait will throw an error if there is nothing to wait for
if tasks:
logger.info("Waiting for running tasks to complete.")
await asyncio.wait(tasks, timeout=self.wait_tasks_timeout)
break

task = asyncio.create_task(
Expand Down
Loading