queue-local 0.0.51__tar.gz → 0.0.53__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.51 → queue_local-0.0.53}/PKG-INFO +1 -1
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local/src/database_queue.py +13 -10
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local.egg-info/PKG-INFO +1 -1
- {queue_local-0.0.51 → queue_local-0.0.53}/setup.py +1 -1
- {queue_local-0.0.51 → queue_local-0.0.53}/README.md +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/pyproject.toml +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local/src/__init__.py +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local/src/our_queue.py +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local.egg-info/requires.txt +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/queue_local.egg-info/top_level.txt +0 -0
- {queue_local-0.0.51 → queue_local-0.0.53}/setup.cfg +0 -0
|
@@ -30,7 +30,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
30
30
|
"""A queue that uses a database table as the queue."""
|
|
31
31
|
|
|
32
32
|
def __init__(self, *, schema_name: str = "queue", table_name: str = "queue_item_table",
|
|
33
|
-
view_name: str = "queue_item_view",
|
|
33
|
+
view_name: str = "queue_item_view", queue_item_id_column_name: str = "queue_item_id",
|
|
34
34
|
is_test_data: bool = False) -> None:
|
|
35
35
|
"""Initialize the queue.
|
|
36
36
|
Make sure the table has the following columns:
|
|
@@ -57,14 +57,15 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
57
57
|
view_name = table_name + "_view"
|
|
58
58
|
if not schema_name:
|
|
59
59
|
schema_name = table_name.split("_")[0]
|
|
60
|
-
self.
|
|
60
|
+
self.queue_item_id_column_name = queue_item_id_column_name
|
|
61
61
|
self.schema_name = schema_name
|
|
62
62
|
|
|
63
63
|
GenericCRUD.__init__(self, default_schema_name=schema_name, default_table_name=table_name,
|
|
64
|
-
default_view_table_name=view_name, default_column_name=
|
|
64
|
+
default_view_table_name=view_name, default_column_name=queue_item_id_column_name,
|
|
65
65
|
is_test_data=is_test_data)
|
|
66
66
|
self.user_context = UserContext()
|
|
67
67
|
|
|
68
|
+
# TODO queue_data_dict
|
|
68
69
|
def push(self, data_dict: dict) -> int:
|
|
69
70
|
"""Pushes a new entry to the queue and returns the new queue id.
|
|
70
71
|
data_dict consists of columns and values to insert into the queue table."""
|
|
@@ -72,16 +73,18 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
72
73
|
|
|
73
74
|
self._fix_parameters_json(data_dict)
|
|
74
75
|
|
|
76
|
+
# TODO data_dict -> queue_dict
|
|
75
77
|
data_dict["queue_status_id"] = QueueStatusEnum.NEW.value
|
|
76
78
|
data_dict["created_user_id"] = created_user_id
|
|
77
79
|
|
|
78
|
-
if self.
|
|
79
|
-
column_value = data_dict[self.
|
|
80
|
-
del data_dict[self.
|
|
80
|
+
if self.queue_item_id_column_name in data_dict:
|
|
81
|
+
column_value = data_dict[self.queue_item_id_column_name]
|
|
82
|
+
del data_dict[self.queue_item_id_column_name]
|
|
81
83
|
self.update_by_column_and_value(column_value=column_value, data_dict=data_dict)
|
|
82
84
|
push_result = column_value
|
|
83
85
|
else:
|
|
84
86
|
push_result = self.insert(data_dict=data_dict)
|
|
87
|
+
# TODO What we return? queue_id, message_id ...? Can we give it more meaningful name?
|
|
85
88
|
return push_result
|
|
86
89
|
# TODO Can we do this everywhere? [I will make it auto in the meta logger]
|
|
87
90
|
# TODO logger.end("...", {'push_result': push_result} )
|
|
@@ -89,7 +92,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
89
92
|
def push_back(self, queue_item: dict) -> None:
|
|
90
93
|
"""Push a taken queue item back to the queue."""
|
|
91
94
|
data_dict = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
|
|
92
|
-
self.update_by_column_and_value(column_value=queue_item[self.
|
|
95
|
+
self.update_by_column_and_value(column_value=queue_item[self.queue_item_id_column_name], data_dict=data_dict)
|
|
93
96
|
|
|
94
97
|
def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
|
|
95
98
|
"""
|
|
@@ -107,7 +110,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
107
110
|
f"AND NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
|
|
108
111
|
(f"AND action_id IN {action_ids} " if action_ids else "") + \
|
|
109
112
|
(f"AND {custom_condition}" if custom_condition else "")
|
|
110
|
-
self.update_by_where(where=update_where, order_by=self.
|
|
113
|
+
self.update_by_where(where=update_where, order_by=self.queue_item_id_column_name, limit=1, data_dict=data_dict)
|
|
111
114
|
|
|
112
115
|
# TODO In which cases queue_status_id IS NULL? - Does it indicate a problem/bug?
|
|
113
116
|
select_where = f"process_id = {os.getpid()} AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})"
|
|
@@ -115,7 +118,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
115
118
|
if queue_item:
|
|
116
119
|
update_data_dict = {"queue_status_id": QueueStatusEnum.RETRIEVED.value,
|
|
117
120
|
"user_jwt": self.user_context.get_user_jwt()}
|
|
118
|
-
self.update_by_column_and_value(column_value=queue_item[self.
|
|
121
|
+
self.update_by_column_and_value(column_value=queue_item[self.queue_item_id_column_name], data_dict=update_data_dict)
|
|
119
122
|
self.logger.info("Entry retrieved and updated from the queue database successfully",
|
|
120
123
|
object=queue_item)
|
|
121
124
|
else:
|
|
@@ -129,7 +132,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
129
132
|
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
130
133
|
# SELECT * FROM `queue`.`queue_item_view` WHERE process_id IS NULL AND queue_status_id = 0
|
|
131
134
|
# AND action_id IN (1, 2, 3) ORDER BY queue_item_id LIMIT 1
|
|
132
|
-
queue_item = self.select_one_dict_by_where(where=where, order_by=self.
|
|
135
|
+
queue_item = self.select_one_dict_by_where(where=where, order_by=self.queue_item_id_column_name)
|
|
133
136
|
return queue_item
|
|
134
137
|
|
|
135
138
|
def _fix_action_ids(self, action_ids):
|
|
@@ -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.53',
|
|
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
|