-
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.
(#64) Support tasks retry & propagate raised exception
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 Signed-off-by: Imran Ariffin <ariffin.imran@gmail.com>
- Loading branch information
1 parent
f02f6ce
commit 8a2e01a
Showing
23 changed files
with
901 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
"""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 `Config`. This object wraps | ||
all the constants, which include: | ||
- Variables | ||
- Environment variables | ||
- Static methods that return constant values | ||
""" | ||
|
||
import logging | ||
from os import environ | ||
|
||
from .interfaces import SerializationType | ||
|
||
_REDIS_URL = "redis://127.0.0.1:6379" | ||
_TASKS_CHANNEL = "channel:tasks" | ||
_RESULTS_CHANNEL_TEMPLATE = "channel:results:{task_id}" | ||
|
||
|
||
class Config: | ||
""" | ||
Provide configuration values. | ||
These include: | ||
- Variables | ||
- Environment variables | ||
- Static methods that return constant values | ||
""" | ||
|
||
@staticmethod | ||
def serialization_type() -> SerializationType: | ||
"""Return the serialization type as provided via env var AIOTASKQ_SERIALIZATION.""" | ||
s: str | None = 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 | ||
|
||
@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
Oops, something went wrong.