From b5d0ffe93cfe5ac1e6ea2bea3200391ac915ebbc Mon Sep 17 00:00:00 2001 From: Vishesh Bansal Date: Tue, 12 Dec 2023 00:56:32 +0530 Subject: [PATCH] code refactor --- tasktiger/_internal.py | 5 +++++ tasktiger/constants.py | 11 ----------- tasktiger/migrations.py | 2 +- tasktiger/redis_scripts.py | 11 +++++++++-- tasktiger/task.py | 4 +++- tasktiger/worker.py | 4 +++- 6 files changed, 21 insertions(+), 16 deletions(-) delete mode 100644 tasktiger/constants.py diff --git a/tasktiger/_internal.py b/tasktiger/_internal.py index 6f31d239..7b00b575 100644 --- a/tasktiger/_internal.py +++ b/tasktiger/_internal.py @@ -27,6 +27,11 @@ from .task import Task from .tasktiger import TaskTiger +# Constants pertaining to Redis keys +TASK = "task" +EXECUTIONS = "executions" +EXECUTIONS_COUNT = "executions_count" + # Task states (represented by different queues) # Note some client code may rely on the string values (e.g. get_queue_stats). QUEUED = "queued" diff --git a/tasktiger/constants.py b/tasktiger/constants.py deleted file mode 100644 index 6baf92dc..00000000 --- a/tasktiger/constants.py +++ /dev/null @@ -1,11 +0,0 @@ -# constants pertaining to Redis keys -REDIS_PREFIX = "t" -TASK = "task" -EXECUTIONS = "executions" -EXECUTIONS_COUNT = "executions_count" - - -QUEUED = "queued" -ACTIVE = "active" -SCHEDULED = "scheduled" -ERROR = "error" diff --git a/tasktiger/migrations.py b/tasktiger/migrations.py index 3a80a2a8..68bbb2c7 100644 --- a/tasktiger/migrations.py +++ b/tasktiger/migrations.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from .constants import EXECUTIONS, TASK +from ._internal import EXECUTIONS, TASK from .utils import redis_glob_escape if TYPE_CHECKING: diff --git a/tasktiger/redis_scripts.py b/tasktiger/redis_scripts.py index 6c068e81..127e1ef7 100644 --- a/tasktiger/redis_scripts.py +++ b/tasktiger/redis_scripts.py @@ -3,8 +3,15 @@ from redis import Redis -from ._internal import ACTIVE, ERROR, QUEUED, SCHEDULED -from .constants import EXECUTIONS, EXECUTIONS_COUNT, TASK +from ._internal import ( + ACTIVE, + ERROR, + EXECUTIONS, + EXECUTIONS_COUNT, + QUEUED, + SCHEDULED, + TASK, +) try: from redis.commands.core import Script diff --git a/tasktiger/task.py b/tasktiger/task.py index c723d32f..0e08fc8f 100644 --- a/tasktiger/task.py +++ b/tasktiger/task.py @@ -20,8 +20,11 @@ from ._internal import ( ERROR, + EXECUTIONS, + EXECUTIONS_COUNT, QUEUED, SCHEDULED, + TASK, g, gen_id, gen_unique_id, @@ -30,7 +33,6 @@ serialize_func_name, serialize_retry_method, ) -from .constants import EXECUTIONS, EXECUTIONS_COUNT, TASK from .exceptions import QueueFullException, TaskImportError, TaskNotFound from .runner import BaseRunner, get_runner_class from .types import RetryStrategy diff --git a/tasktiger/worker.py b/tasktiger/worker.py index b322540f..9f944e49 100644 --- a/tasktiger/worker.py +++ b/tasktiger/worker.py @@ -36,8 +36,11 @@ from ._internal import ( ACTIVE, ERROR, + EXECUTIONS, + EXECUTIONS_COUNT, QUEUED, SCHEDULED, + TASK, dotted_parts, g, g_fork_lock, @@ -47,7 +50,6 @@ serialize_func_name, serialize_retry_method, ) -from .constants import EXECUTIONS, EXECUTIONS_COUNT, TASK from .exceptions import ( RetryException, StopRetry,