queue-local 0.0.26__tar.gz → 0.0.28__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.26 → queue-local-0.0.28}/PKG-INFO +1 -1
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local/src/database_queue.py +17 -11
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local.egg-info/PKG-INFO +1 -1
- {queue-local-0.0.26 → queue-local-0.0.28}/setup.py +1 -1
- {queue-local-0.0.26 → queue-local-0.0.28}/README.md +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/pyproject.toml +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local/src/__init__.py +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local/src/our_queue.py +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local.egg-info/requires.txt +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/queue_local.egg-info/top_level.txt +0 -0
- {queue-local-0.0.26 → queue-local-0.0.28}/setup.cfg +0 -0
|
@@ -52,7 +52,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
52
52
|
default_id_column_name=id_column_name, connection=connection)
|
|
53
53
|
self.logger.info("DatabaseQueue initialized successfully", object={
|
|
54
54
|
"schema_name": schema_name, "table_name": table_name, "view_name": view_name, "id_column_name": id_column_name})
|
|
55
|
-
UserContext
|
|
55
|
+
self.user = UserContext()
|
|
56
56
|
|
|
57
57
|
def push(self, data_json: dict) -> None:
|
|
58
58
|
"""Pushes a new entry to the queue.
|
|
@@ -63,7 +63,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
63
63
|
try:
|
|
64
64
|
self._fix_parameters_json(data_json)
|
|
65
65
|
|
|
66
|
-
data_json["
|
|
66
|
+
data_json["queue_status_id"] = StatusEnum.NEW.value
|
|
67
67
|
data_json["created_user_id"] = created_user_id
|
|
68
68
|
|
|
69
69
|
self.insert(data_json=data_json)
|
|
@@ -75,7 +75,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
75
75
|
def push_back(self, queue_item: dict) -> None:
|
|
76
76
|
"""Push a taken queue item back to the queue."""
|
|
77
77
|
self.logger.start("Pushing back queue item", object=str(queue_item))
|
|
78
|
-
data_json = {"
|
|
78
|
+
data_json = {"queue_status_id": StatusEnum.NEW.value, "process_id": None}
|
|
79
79
|
self.update_by_id(id_column_value=queue_item[self.id_column_name], data_json=data_json)
|
|
80
80
|
self.logger.end("Queue item pushed back successfully")
|
|
81
81
|
|
|
@@ -86,22 +86,26 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
86
86
|
:param action_ids: Tuple of action IDs to consider (optional).
|
|
87
87
|
:return: Dictionary representing the retrieved queue item.
|
|
88
88
|
"""
|
|
89
|
-
updated_user_id =
|
|
89
|
+
updated_user_id = self.user.get_effective_user_id()
|
|
90
90
|
self.logger.start("Getting and updating queue item from the queue database", object={"action_ids": action_ids})
|
|
91
91
|
action_ids = self._fix_action_ids(action_ids)
|
|
92
92
|
|
|
93
93
|
try:
|
|
94
94
|
data_json = {"process_id": os.getpid()}
|
|
95
|
-
update_where = f"process_id IS NULL AND
|
|
95
|
+
update_where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value}" + \
|
|
96
96
|
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
97
97
|
self.update_by_where(where=update_where, order_by="created_timestamp", limit=1, data_json=data_json)
|
|
98
98
|
|
|
99
|
-
select_where = f"process_id = {os.getpid()} AND
|
|
99
|
+
select_where = f"process_id = {os.getpid()} AND queue_status_id = {StatusEnum.NEW.value}"
|
|
100
100
|
queue_item = self.select_one_dict_by_where(where=select_where)
|
|
101
101
|
if queue_item:
|
|
102
102
|
# Update the selected queue item
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
query = f"UPDATE {self.default_table_name} " \
|
|
104
|
+
f"SET queue_status_id = %s, updated_user_id = %s, user_jwt=%s, start_timestamp = NOW() " \
|
|
105
|
+
f"WHERE {self.id_column_name} = %s"
|
|
106
|
+
params = (StatusEnum.RETRIEVED.value, updated_user_id, self.user.get_user_JWT(),
|
|
107
|
+
queue_item[self.id_column_name])
|
|
108
|
+
self.cursor.execute(query, params)
|
|
105
109
|
self.logger.end("Entry retrieved and updated from the queue database successfully",
|
|
106
110
|
object={k: str(v) for k, v in queue_item.items()}) # contains a datetime object
|
|
107
111
|
else:
|
|
@@ -112,12 +116,14 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
112
116
|
raise
|
|
113
117
|
return queue_item
|
|
114
118
|
|
|
115
|
-
def peek(self) -> dict:
|
|
119
|
+
def peek(self, action_ids: tuple = ()) -> dict:
|
|
116
120
|
"""Get the first item in the queue without changing it"""
|
|
121
|
+
action_ids = self._fix_action_ids(action_ids)
|
|
122
|
+
where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value}" + \
|
|
123
|
+
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
117
124
|
try:
|
|
118
125
|
self.logger.start("Peeking queue item from the queue database")
|
|
119
|
-
queue_item = self.
|
|
120
|
-
id_column_value=StatusEnum.NEW.value, order_by="created_timestamp")
|
|
126
|
+
queue_item = self.select_one_dict_by_where(where=where, order_by="created_timestamp")
|
|
121
127
|
self.logger.end("Entry peeked from the queue database successfully" if queue_item else "The queue is empty")
|
|
122
128
|
except Exception as e:
|
|
123
129
|
self.logger.exception("Error while peeking queue item from the queue database", object=e)
|
|
@@ -8,7 +8,7 @@ with open('README.md') as f:
|
|
|
8
8
|
|
|
9
9
|
setuptools.setup(
|
|
10
10
|
name=PACKAGE_NAME, # https://pypi.org/project/queue-local
|
|
11
|
-
version='0.0.
|
|
11
|
+
version='0.0.28',
|
|
12
12
|
author="Circles",
|
|
13
13
|
author_email="info@circles.life",
|
|
14
14
|
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
|