-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
For documentation, see: 1. Docstring of `task.task` 2. Tests in `tests.test_task` e.g. `test_retry_as_per_task_definition` 3. Sample usages in `tests.apps.simple_app` e.g. `append_to_file` Changelist: * Formalize serialization and deserialization * Serialize & deserialize exceptions correctly * Encapsulate retry & retry_on in a new dict 'options' * Implement serde for AsyncResult * Ensure generated file deleted after test * Add jsonpickle to toml file * Exclude `if TYPE_CHECKING:` from coverage * Add test for singleton * Add logging for worker * Wrap all constants inside `Config` class * Handle case when `options.retry.on` is empty Signed-off-by: Imran Ariffin <ariffin.imran@gmail.com> Requested changes: * Rename constants.py to config.py * Split file into config.py & constants.py * Avoid retrying forever * Move logic from `AsyncResult.from_publisher` to `Task._get_result`. This way `AsyncResult` can be just a pure class with no side-effect Fixups: * Fix docker-compose cmd not found on GithubAction
- Loading branch information
1 parent
f02f6ce
commit a6b0149
Showing
27 changed files
with
972 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Module to define and store all configuration values used across the library. | ||
The public object from this module is `Config`. This object wraps | ||
all the configuration values, which include: | ||
- Variables | ||
- Environment variables | ||
""" | ||
|
||
import logging | ||
from os import environ | ||
|
||
from .interfaces import SerializationType | ||
|
||
_REDIS_URL = "redis://127.0.0.1:6379" | ||
|
||
|
||
class Config: | ||
""" | ||
Provide configuration values. | ||
These include: | ||
- Variables | ||
- Environment variables | ||
""" | ||
|
||
@staticmethod | ||
def serialization_type() -> SerializationType: | ||
"""Return the serialization type as provided via env var AIOTASKQ_SERIALIZATION.""" | ||
s: str = environ.get("AIOTASKQ_SERIALIZATION", SerializationType.DEFAULT.value) | ||
return SerializationType[s.upper()] | ||
|
||
@staticmethod | ||
def log_level() -> int: | ||
"""Return the log level as provided via env var LOG_LEVEL.""" | ||
level: int = int(environ.get("AIOTASKQ_LOG_LEVEL", logging.DEBUG)) | ||
return level | ||
|
||
@staticmethod | ||
def broker_url() -> str: | ||
""" | ||
Return the broker url as provided via env var BROKER_URL. | ||
Defaults to "redis://127.0.0.1:6379". | ||
""" | ||
broker_url: str = environ.get("BROKER_URL", _REDIS_URL) | ||
return broker_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
"""Module to define and store all constants used across the library.""" | ||
""" | ||
Module to define and store all constants used across the library. | ||
REDIS_URL = "redis://127.0.0.1:6379" | ||
TASKS_CHANNEL = "channel:tasks" | ||
RESULTS_CHANNEL_TEMPLATE = "channel:results:{task_id}" | ||
The public object from this module is `Constants`. This object wraps | ||
all the constants, which include: | ||
- Static methods that return constant values | ||
""" | ||
|
||
|
||
_TASKS_CHANNEL = "channel:tasks" | ||
_RESULTS_CHANNEL_TEMPLATE = "channel:results:{task_id}" | ||
|
||
|
||
class Constants: | ||
""" | ||
Provide all the constants. | ||
These include: | ||
- Static methods that return constant values | ||
""" | ||
|
||
@staticmethod | ||
def tasks_channel() -> str: | ||
"""Return the channel name used for transporting task requests on the broker.""" | ||
return _TASKS_CHANNEL | ||
|
||
@staticmethod | ||
def results_channel_template() -> str: | ||
"""Return the template chnnale name used for transporting task results on the broker.""" | ||
return _RESULTS_CHANNEL_TEMPLATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.