queue-local 0.0.50__tar.gz → 0.0.51__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.50 → queue_local-0.0.51}/PKG-INFO +1 -1
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local/src/database_queue.py +10 -12
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local.egg-info/PKG-INFO +1 -1
- {queue_local-0.0.50 → queue_local-0.0.51}/setup.py +1 -1
- {queue_local-0.0.50 → queue_local-0.0.51}/README.md +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/pyproject.toml +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local/src/__init__.py +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local/src/our_queue.py +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local.egg-info/requires.txt +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/queue_local.egg-info/top_level.txt +0 -0
- {queue_local-0.0.50 → queue_local-0.0.51}/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_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,15 +57,14 @@ 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_id_column_name = queue_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_id_column_name,
|
|
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:
|
|
70
69
|
"""Pushes a new entry to the queue and returns the new queue id.
|
|
71
70
|
data_dict consists of columns and values to insert into the queue table."""
|
|
@@ -76,14 +75,13 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
76
75
|
data_dict["queue_status_id"] = QueueStatusEnum.NEW.value
|
|
77
76
|
data_dict["created_user_id"] = created_user_id
|
|
78
77
|
|
|
79
|
-
if self.
|
|
80
|
-
column_value = data_dict[self.
|
|
81
|
-
del data_dict[self.
|
|
78
|
+
if self.queue_id_column_name in data_dict:
|
|
79
|
+
column_value = data_dict[self.queue_id_column_name]
|
|
80
|
+
del data_dict[self.queue_id_column_name]
|
|
82
81
|
self.update_by_column_and_value(column_value=column_value, data_dict=data_dict)
|
|
83
82
|
push_result = column_value
|
|
84
83
|
else:
|
|
85
84
|
push_result = self.insert(data_dict=data_dict)
|
|
86
|
-
# TODO What we return? queue_id, message_id ...? Can we give it more meaningful name?
|
|
87
85
|
return push_result
|
|
88
86
|
# TODO Can we do this everywhere? [I will make it auto in the meta logger]
|
|
89
87
|
# TODO logger.end("...", {'push_result': push_result} )
|
|
@@ -91,7 +89,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
91
89
|
def push_back(self, queue_item: dict) -> None:
|
|
92
90
|
"""Push a taken queue item back to the queue."""
|
|
93
91
|
data_dict = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
|
|
94
|
-
self.update_by_column_and_value(column_value=queue_item[self.
|
|
92
|
+
self.update_by_column_and_value(column_value=queue_item[self.queue_id_column_name], data_dict=data_dict)
|
|
95
93
|
|
|
96
94
|
def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
|
|
97
95
|
"""
|
|
@@ -109,7 +107,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
109
107
|
f"AND NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
|
|
110
108
|
(f"AND action_id IN {action_ids} " if action_ids else "") + \
|
|
111
109
|
(f"AND {custom_condition}" if custom_condition else "")
|
|
112
|
-
self.update_by_where(where=update_where, order_by=self.
|
|
110
|
+
self.update_by_where(where=update_where, order_by=self.queue_id_column_name, limit=1, data_dict=data_dict)
|
|
113
111
|
|
|
114
112
|
# TODO In which cases queue_status_id IS NULL? - Does it indicate a problem/bug?
|
|
115
113
|
select_where = f"process_id = {os.getpid()} AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})"
|
|
@@ -117,7 +115,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
117
115
|
if queue_item:
|
|
118
116
|
update_data_dict = {"queue_status_id": QueueStatusEnum.RETRIEVED.value,
|
|
119
117
|
"user_jwt": self.user_context.get_user_jwt()}
|
|
120
|
-
self.update_by_column_and_value(column_value=queue_item[self.
|
|
118
|
+
self.update_by_column_and_value(column_value=queue_item[self.queue_id_column_name], data_dict=update_data_dict)
|
|
121
119
|
self.logger.info("Entry retrieved and updated from the queue database successfully",
|
|
122
120
|
object=queue_item)
|
|
123
121
|
else:
|
|
@@ -131,7 +129,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
131
129
|
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
132
130
|
# SELECT * FROM `queue`.`queue_item_view` WHERE process_id IS NULL AND queue_status_id = 0
|
|
133
131
|
# AND action_id IN (1, 2, 3) ORDER BY queue_item_id LIMIT 1
|
|
134
|
-
queue_item = self.select_one_dict_by_where(where=where, order_by=self.
|
|
132
|
+
queue_item = self.select_one_dict_by_where(where=where, order_by=self.queue_id_column_name)
|
|
135
133
|
return queue_item
|
|
136
134
|
|
|
137
135
|
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.51',
|
|
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
|