Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
WaYdotNET committed Dec 4, 2023
1 parent d8b703c commit 637622c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions celery_pubsub/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
P: TypeAlias = typing.Any # ParamSpec
R: TypeAlias = typing.Any # Return type

task: typing.Callable[..., typing.Callable[[typing.Callable[[P], R]], Task[P, R]]] = celery.shared_task
task: typing.Callable[
..., typing.Callable[[typing.Callable[[P], R]], Task[P, R]]
] = celery.shared_task


class PubSubManager:
Expand Down Expand Up @@ -87,9 +89,12 @@ def _topic_to_re(topic: str) -> re.Pattern[str]:

def subscribe_to(topic: str) -> typing.Callable[[typing.Callable[[P], R]], Task[P, R]]:
def decorator(func: typing.Callable[[P], R]) -> Task[P, R]:
app_name, module_name = func.__module__.split(".", 1)
task_name = f"{app_name}.{module_name}.{func.__qualname__}"
task_instance = func if isinstance(func, Task) else task(name=task_name)(func)
if isinstance(func, Task):
task_instance: Task[P, R] = func
else:
app_name, module_name = func.__module__.split(".", 1)
task_name = f"{app_name}.{module_name}.{func.__qualname__}"
task_instance = task(name=task_name)(func)
_pubsub_manager.subscribe(topic, task_instance)
return task_instance

Expand Down

0 comments on commit 637622c

Please sign in to comment.