-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add factories #349
base: develop
Are you sure you want to change the base?
Add factories #349
Changes from 3 commits
872351e
bf9f7ac
7662f23
4de11ca
fb3cf32
c52a5f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from taskiq.abc.broker import AsyncBroker | ||
|
||
|
||
class BrokerFactory(ABC): | ||
"""BrokerFactory class.""" | ||
|
||
@abstractmethod | ||
def get_broker(self) -> AsyncBroker: | ||
""" | ||
Get broker instance. | ||
|
||
:return: AsyncBroker instance | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from taskiq import TaskiqScheduler | ||
|
||
|
||
class TaskiqSchedulerFactory(ABC): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question. |
||
"""SchedulerFactory class.""" | ||
|
||
@abstractmethod | ||
def get_scheduler(self) -> TaskiqScheduler: | ||
""" | ||
Get scheduler instance. | ||
|
||
:return: TaskiqScheduler instance | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from dataclasses import dataclass | ||
from typing import List, Optional, Sequence, Union | ||
|
||
from taskiq.abc.scheduler_factory import TaskiqSchedulerFactory | ||
from taskiq.cli.common_args import LogLevel | ||
from taskiq.scheduler.scheduler import TaskiqScheduler | ||
|
||
|
@@ -10,8 +11,9 @@ | |
class SchedulerArgs: | ||
"""Arguments for scheduler.""" | ||
|
||
scheduler: Union[str, TaskiqScheduler] | ||
modules: List[str] | ||
scheduler: Union[str, TaskiqScheduler] = "" | ||
scheduler_factory: Union[str, TaskiqSchedulerFactory] = "" | ||
log_level: str = LogLevel.INFO.name | ||
configure_logging: bool = True | ||
fs_discover: bool = False | ||
|
@@ -32,7 +34,21 @@ def from_cli(cls, args: Optional[Sequence[str]] = None) -> "SchedulerArgs": | |
formatter_class=ArgumentDefaultsHelpFormatter, | ||
description="Subcommand to run scheduler", | ||
) | ||
parser.add_argument("scheduler", help="Path to scheduler") | ||
parser.add_argument( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need two parameters. Specify only factory. We can check if the imported scheduler is a factory after we import it. |
||
"--scheduler", | ||
default=None, | ||
help="Path to scheduler", | ||
) | ||
parser.add_argument( | ||
"--scheduler-factory", | ||
"-sf", | ||
default=None, | ||
help=( | ||
"Where to search for SchedulerFactory. " | ||
"This string must be specified in " | ||
"'module.module:ClassName' format." | ||
), | ||
) | ||
parser.add_argument( | ||
"modules", | ||
help="List of modules where to look for tasks.", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,9 @@ def receiver_arg_type(string: str) -> Tuple[str, str]: | |
class WorkerArgs: | ||
"""Taskiq worker CLI arguments.""" | ||
|
||
broker: str | ||
modules: List[str] | ||
broker: Optional[str] = None | ||
broker_factory: Optional[str] = None | ||
tasks_pattern: Sequence[str] = ("**/tasks.py",) | ||
fs_discover: bool = False | ||
configure_logging: bool = True | ||
|
@@ -59,13 +60,24 @@ def from_cli( | |
""" | ||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) | ||
parser.add_argument( | ||
"broker", | ||
"--broker", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as for the scheduler. |
||
default=None, | ||
help=( | ||
"Where to search for broker. " | ||
"This string must be specified in " | ||
"'module.module:variable' format." | ||
), | ||
) | ||
parser.add_argument( | ||
"--broker-factory", | ||
"-bf", | ||
default=None, | ||
help=( | ||
"Where to search for BrokerFactory. " | ||
"This string must be specified in " | ||
"'module.module:ClassName' format." | ||
), | ||
) | ||
parser.add_argument( | ||
"--receiver", | ||
default="taskiq.receiver:Receiver", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a class for that? Shouldn't just path to function be enough?