queue-local 0.0.54__tar.gz → 0.0.56__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {queue_local-0.0.54 → queue_local-0.0.56}/PKG-INFO +1 -1
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local/src/database_queue.py +34 -29
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local.egg-info/PKG-INFO +1 -1
- {queue_local-0.0.54 → queue_local-0.0.56}/setup.py +1 -1
- {queue_local-0.0.54 → queue_local-0.0.56}/README.md +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/pyproject.toml +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local/src/__init__.py +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local/src/our_queue.py +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local.egg-info/requires.txt +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/queue_local.egg-info/top_level.txt +0 -0
- {queue_local-0.0.54 → queue_local-0.0.56}/setup.cfg +0 -0
|
@@ -2,15 +2,15 @@ import json
|
|
|
2
2
|
import os
|
|
3
3
|
from collections.abc import Iterable
|
|
4
4
|
from enum import Enum
|
|
5
|
-
|
|
6
5
|
from database_mysql_local.generic_crud import GenericCRUD
|
|
7
6
|
from logger_local.LoggerComponentEnum import LoggerComponentEnum
|
|
8
7
|
from logger_local.MetaLogger import MetaLogger
|
|
9
8
|
from user_context_remote.user_context import UserContext
|
|
10
9
|
|
|
10
|
+
|
|
11
11
|
from .our_queue import OurQueue
|
|
12
12
|
|
|
13
|
-
QUEUE_LOCAL_PYTHON_COMPONENT_ID =
|
|
13
|
+
QUEUE_LOCAL_PYTHON_COMPONENT_ID = 156
|
|
14
14
|
QUEUE_LOCAL_PYTHON_COMPONENT_NAME = "queue_local/src/database_queue.py"
|
|
15
15
|
DEVELOPER_EMAIL = 'akiva.s@circ.zone'
|
|
16
16
|
queue_logger_object = {
|
|
@@ -65,36 +65,37 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
65
65
|
is_test_data=is_test_data)
|
|
66
66
|
self.user_context = UserContext()
|
|
67
67
|
|
|
68
|
-
# TODO queue_data_dict
|
|
69
68
|
def push(self, data_dict: dict) -> int:
|
|
69
|
+
queue_dict=data_dict
|
|
70
70
|
"""Pushes a new entry to the queue and returns the new queue id.
|
|
71
|
-
|
|
71
|
+
queue_dict consists of columns and values to insert into the queue table."""
|
|
72
72
|
created_user_id = UserContext().get_effective_user_id()
|
|
73
73
|
|
|
74
|
-
self._fix_parameters_json(
|
|
74
|
+
self._fix_parameters_json(queue_dict)
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
queue_dict["queue_status_id"] = QueueStatusEnum.NEW.value
|
|
77
|
+
|
|
78
|
+
queue_dict["created_user_id"] = created_user_id
|
|
79
79
|
|
|
80
|
-
if self.queue_item_id_column_name in
|
|
81
|
-
column_value =
|
|
82
|
-
del
|
|
83
|
-
self.update_by_column_and_value(column_value=column_value,
|
|
84
|
-
|
|
80
|
+
if self.queue_item_id_column_name in queue_dict:
|
|
81
|
+
column_value = queue_dict[self.queue_item_id_column_name]
|
|
82
|
+
del queue_dict[self.queue_item_id_column_name]
|
|
83
|
+
self.update_by_column_and_value(column_value=column_value, queue_dict=queue_dict)
|
|
84
|
+
queue_id = column_value
|
|
85
85
|
else:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
86
|
+
queue_id = self.insert(data_dict=queue_dict)
|
|
87
|
+
self.logger.end("...", object={'push_result': queue_id} )
|
|
88
|
+
return queue_id
|
|
89
89
|
# TODO Can we do this everywhere? [I will make it auto in the meta logger]
|
|
90
|
-
# TODO logger.end("...", {'push_result': push_result} )
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
|
|
92
|
+
def push_back(self, queue_item: dict = None, data_dict: dict = None) -> None:
|
|
93
93
|
"""Push a taken queue item back to the queue."""
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
queue_dict = queue_item or data_dict
|
|
95
|
+
queue_dict = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
|
|
96
|
+
self.update_by_column_and_value(column_value=queue_item[self.queue_item_id_column_name], queue_dict=queue_dict)
|
|
96
97
|
|
|
97
|
-
def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
|
|
98
|
+
def get(self, *, action_ids: tuple = (), custom_condition: str = "",data_dict: dict = None) -> dict:
|
|
98
99
|
"""
|
|
99
100
|
Returns the first item from the queue (possibly considering specific actions) and marks it as taken.
|
|
100
101
|
|
|
@@ -102,23 +103,24 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
102
103
|
:param custom_condition: Custom condition to add to the WHERE clause (optional).
|
|
103
104
|
:return: Dictionary representing the retrieved queue item.
|
|
104
105
|
"""
|
|
106
|
+
queue_dict=data_dict
|
|
105
107
|
action_ids = self._fix_action_ids(action_ids)
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
queue_dict = {"process_id": os.getpid()}
|
|
108
110
|
update_where = f"process_id IS NULL " \
|
|
109
111
|
f"AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value}) " \
|
|
110
112
|
f"AND NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
|
|
111
113
|
(f"AND action_id IN {action_ids} " if action_ids else "") + \
|
|
112
114
|
(f"AND {custom_condition}" if custom_condition else "")
|
|
113
|
-
self.update_by_where(where=update_where, order_by=self.queue_item_id_column_name, limit=1, data_dict=
|
|
115
|
+
self.update_by_where(where=update_where, order_by=self.queue_item_id_column_name, limit=1, data_dict=queue_dict)
|
|
114
116
|
|
|
115
|
-
# TODO In which cases queue_status_id IS NULL? - Does it indicate a problem/bug?
|
|
116
117
|
select_where = f"process_id = {os.getpid()} AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})"
|
|
118
|
+
|
|
117
119
|
queue_item = self.select_one_dict_by_where(where=select_where)
|
|
118
120
|
if queue_item:
|
|
119
|
-
|
|
121
|
+
update_queue_dict = {"queue_status_id": QueueStatusEnum.RETRIEVED.value,
|
|
120
122
|
"user_jwt": self.user_context.get_user_jwt()}
|
|
121
|
-
self.update_by_column_and_value(column_value=queue_item[self.queue_item_id_column_name], data_dict=
|
|
123
|
+
self.update_by_column_and_value(column_value=queue_item[self.queue_item_id_column_name], data_dict=update_queue_dict)
|
|
122
124
|
self.logger.info("Entry retrieved and updated from the queue database successfully",
|
|
123
125
|
object=queue_item)
|
|
124
126
|
else:
|
|
@@ -148,10 +150,13 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
148
150
|
|
|
149
151
|
@staticmethod
|
|
150
152
|
def _fix_parameters_json(data_dict: dict):
|
|
153
|
+
queue_dict=data_dict
|
|
151
154
|
"""Fixes the parameters_json argument to fit the SQL syntax (parameters_json must be a string)"""
|
|
152
|
-
for key, value in
|
|
155
|
+
for key, value in queue_dict.items():
|
|
153
156
|
if "parameters_json" in key:
|
|
154
157
|
if isinstance(value, str):
|
|
155
|
-
|
|
158
|
+
queue_dict[key] = value.replace("'", '"')
|
|
156
159
|
else:
|
|
157
|
-
|
|
160
|
+
queue_dict[key] = json.dumps(value)
|
|
161
|
+
|
|
162
|
+
|
|
@@ -5,7 +5,7 @@ package_dir = PACKAGE_NAME.replace("-", "_")
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name=PACKAGE_NAME, # https://pypi.org/project/queue-local
|
|
8
|
-
version='0.0.
|
|
8
|
+
version='0.0.56',
|
|
9
9
|
author="Circles",
|
|
10
10
|
author_email="info@circles.life",
|
|
11
11
|
url=f"https://github.com/circles-zone/{PACKAGE_NAME}-python-package",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|