queue-local 0.0.48__tar.gz → 0.0.50__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.48 → queue_local-0.0.50}/PKG-INFO +3 -3
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local/src/database_queue.py +33 -45
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local.egg-info/PKG-INFO +3 -3
- queue_local-0.0.50/queue_local.egg-info/requires.txt +3 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/setup.py +3 -3
- queue_local-0.0.48/queue_local.egg-info/requires.txt +0 -3
- {queue_local-0.0.48 → queue_local-0.0.50}/README.md +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/pyproject.toml +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local/src/__init__.py +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local/src/our_queue.py +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/queue_local.egg-info/top_level.txt +0 -0
- {queue_local-0.0.48 → queue_local-0.0.50}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: queue-local
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.50
|
|
4
4
|
Home-page: https://github.com/circles-zone/queue-local-python-package
|
|
5
5
|
Author: Circles
|
|
6
6
|
Author-email: info@circles.life
|
|
@@ -8,8 +8,8 @@ Classifier: Programming Language :: Python :: 3
|
|
|
8
8
|
Classifier: License :: Other/Proprietary License
|
|
9
9
|
Classifier: Operating System :: OS Independent
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
|
-
Requires-Dist: database-mysql-local>=0.0.
|
|
12
|
-
Requires-Dist: logger-local>=0.0.
|
|
11
|
+
Requires-Dist: database-mysql-local>=0.0.292
|
|
12
|
+
Requires-Dist: logger-local>=0.0.135
|
|
13
13
|
Requires-Dist: user-context-remote>=0.0.30
|
|
14
14
|
|
|
15
15
|
queue-local
|
|
@@ -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", 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:
|
|
@@ -50,9 +50,6 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
50
50
|
(or "_view" added to the end if there is no "_table").
|
|
51
51
|
You can pass a Connector object to use an existing connection, or None to create a new connection.
|
|
52
52
|
"""
|
|
53
|
-
self.logger.start("Initializing DatabaseQueue", object={
|
|
54
|
-
"schema_name": schema_name, "table_name": table_name,
|
|
55
|
-
"view_name": view_name, "id_column_name": id_column_name})
|
|
56
53
|
if not view_name:
|
|
57
54
|
if table_name.endswith("_table"):
|
|
58
55
|
view_name = table_name.replace("_table", "_view")
|
|
@@ -60,43 +57,41 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
60
57
|
view_name = table_name + "_view"
|
|
61
58
|
if not schema_name:
|
|
62
59
|
schema_name = table_name.split("_")[0]
|
|
63
|
-
self.
|
|
60
|
+
self.column_name = column_name
|
|
61
|
+
self.schema_name = schema_name
|
|
64
62
|
|
|
65
63
|
GenericCRUD.__init__(self, default_schema_name=schema_name, default_table_name=table_name,
|
|
66
|
-
default_view_table_name=view_name,
|
|
64
|
+
default_view_table_name=view_name, default_column_name=column_name,
|
|
67
65
|
is_test_data=is_test_data)
|
|
68
|
-
self.user_context = UserContext()
|
|
69
|
-
self.logger.end("DatabaseQueue initialized successfully", object={
|
|
70
|
-
"schema_name": schema_name, "table_name": table_name,
|
|
71
|
-
"view_name": view_name, "id_column_name": id_column_name})
|
|
66
|
+
self.user_context = UserContext()
|
|
72
67
|
|
|
73
|
-
|
|
68
|
+
# TODO queue_data_dict
|
|
69
|
+
def push(self, data_dict: dict) -> int:
|
|
74
70
|
"""Pushes a new entry to the queue and returns the new queue id.
|
|
75
|
-
|
|
71
|
+
data_dict consists of columns and values to insert into the queue table."""
|
|
76
72
|
created_user_id = UserContext().get_effective_user_id()
|
|
77
73
|
|
|
78
|
-
self._fix_parameters_json(
|
|
74
|
+
self._fix_parameters_json(data_dict)
|
|
79
75
|
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
data_dict["queue_status_id"] = QueueStatusEnum.NEW.value
|
|
77
|
+
data_dict["created_user_id"] = created_user_id
|
|
82
78
|
|
|
83
|
-
if self.
|
|
84
|
-
|
|
85
|
-
del
|
|
86
|
-
self.
|
|
87
|
-
|
|
88
|
-
return id_column_value
|
|
79
|
+
if self.column_name in data_dict:
|
|
80
|
+
column_value = data_dict[self.column_name]
|
|
81
|
+
del data_dict[self.column_name]
|
|
82
|
+
self.update_by_column_and_value(column_value=column_value, data_dict=data_dict)
|
|
83
|
+
push_result = column_value
|
|
89
84
|
else:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
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
|
+
return push_result
|
|
88
|
+
# TODO Can we do this everywhere? [I will make it auto in the meta logger]
|
|
93
89
|
# TODO logger.end("...", {'push_result': push_result} )
|
|
94
|
-
# TODO return push_result
|
|
95
90
|
|
|
96
91
|
def push_back(self, queue_item: dict) -> None:
|
|
97
92
|
"""Push a taken queue item back to the queue."""
|
|
98
|
-
|
|
99
|
-
self.
|
|
93
|
+
data_dict = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
|
|
94
|
+
self.update_by_column_and_value(column_value=queue_item[self.column_name], data_dict=data_dict)
|
|
100
95
|
|
|
101
96
|
def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
|
|
102
97
|
"""
|
|
@@ -106,29 +101,23 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
106
101
|
:param custom_condition: Custom condition to add to the WHERE clause (optional).
|
|
107
102
|
:return: Dictionary representing the retrieved queue item.
|
|
108
103
|
"""
|
|
109
|
-
updated_user_id = self.user_context.get_effective_user_id()
|
|
110
104
|
action_ids = self._fix_action_ids(action_ids)
|
|
111
105
|
|
|
112
|
-
|
|
106
|
+
data_dict = {"process_id": os.getpid()}
|
|
113
107
|
update_where = f"process_id IS NULL " \
|
|
114
108
|
f"AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value}) " \
|
|
115
109
|
f"AND NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
|
|
116
110
|
(f"AND action_id IN {action_ids} " if action_ids else "") + \
|
|
117
111
|
(f"AND {custom_condition}" if custom_condition else "")
|
|
118
|
-
self.update_by_where(where=update_where, order_by=self.
|
|
112
|
+
self.update_by_where(where=update_where, order_by=self.column_name, limit=1, data_dict=data_dict)
|
|
119
113
|
|
|
120
114
|
# TODO In which cases queue_status_id IS NULL? - Does it indicate a problem/bug?
|
|
121
115
|
select_where = f"process_id = {os.getpid()} AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})"
|
|
122
116
|
queue_item = self.select_one_dict_by_where(where=select_where)
|
|
123
117
|
if queue_item:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
f"WHERE {self.id_column_name} = %s"
|
|
128
|
-
params = (QueueStatusEnum.RETRIEVED.value, updated_user_id, self.user_context.get_user_jwt(),
|
|
129
|
-
queue_item[self.id_column_name])
|
|
130
|
-
self.cursor.execute(query, params)
|
|
131
|
-
self.connection.commit()
|
|
118
|
+
update_data_dict = {"queue_status_id": QueueStatusEnum.RETRIEVED.value,
|
|
119
|
+
"user_jwt": self.user_context.get_user_jwt()}
|
|
120
|
+
self.update_by_column_and_value(column_value=queue_item[self.column_name], data_dict=update_data_dict)
|
|
132
121
|
self.logger.info("Entry retrieved and updated from the queue database successfully",
|
|
133
122
|
object=queue_item)
|
|
134
123
|
else:
|
|
@@ -138,12 +127,11 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
138
127
|
def peek(self, action_ids: tuple = ()) -> dict:
|
|
139
128
|
"""Get the first item in the queue without changing it"""
|
|
140
129
|
action_ids = self._fix_action_ids(action_ids)
|
|
141
|
-
|
|
142
|
-
where = f"process_id IS NULL AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})" + \
|
|
130
|
+
where = f"process_id IS NULL AND queue_status_id = {QueueStatusEnum.NEW.value}" + \
|
|
143
131
|
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
144
132
|
# SELECT * FROM `queue`.`queue_item_view` WHERE process_id IS NULL AND queue_status_id = 0
|
|
145
133
|
# AND action_id IN (1, 2, 3) ORDER BY queue_item_id LIMIT 1
|
|
146
|
-
queue_item = self.select_one_dict_by_where(where=where, order_by=self.
|
|
134
|
+
queue_item = self.select_one_dict_by_where(where=where, order_by=self.column_name)
|
|
147
135
|
return queue_item
|
|
148
136
|
|
|
149
137
|
def _fix_action_ids(self, action_ids):
|
|
@@ -158,11 +146,11 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
158
146
|
return action_ids if len(action_ids) != 1 else f"({action_ids[0]})"
|
|
159
147
|
|
|
160
148
|
@staticmethod
|
|
161
|
-
def _fix_parameters_json(
|
|
149
|
+
def _fix_parameters_json(data_dict: dict):
|
|
162
150
|
"""Fixes the parameters_json argument to fit the SQL syntax (parameters_json must be a string)"""
|
|
163
|
-
for key, value in
|
|
151
|
+
for key, value in data_dict.items():
|
|
164
152
|
if "parameters_json" in key:
|
|
165
153
|
if isinstance(value, str):
|
|
166
|
-
|
|
154
|
+
data_dict[key] = value.replace("'", '"')
|
|
167
155
|
else:
|
|
168
|
-
|
|
156
|
+
data_dict[key] = json.dumps(value)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: queue-local
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.50
|
|
4
4
|
Home-page: https://github.com/circles-zone/queue-local-python-package
|
|
5
5
|
Author: Circles
|
|
6
6
|
Author-email: info@circles.life
|
|
@@ -8,8 +8,8 @@ Classifier: Programming Language :: Python :: 3
|
|
|
8
8
|
Classifier: License :: Other/Proprietary License
|
|
9
9
|
Classifier: Operating System :: OS Independent
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
|
-
Requires-Dist: database-mysql-local>=0.0.
|
|
12
|
-
Requires-Dist: logger-local>=0.0.
|
|
11
|
+
Requires-Dist: database-mysql-local>=0.0.292
|
|
12
|
+
Requires-Dist: logger-local>=0.0.135
|
|
13
13
|
Requires-Dist: user-context-remote>=0.0.30
|
|
14
14
|
|
|
15
15
|
queue-local
|
|
@@ -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.50',
|
|
9
9
|
author="Circles",
|
|
10
10
|
author_email="info@circles.life",
|
|
11
11
|
url=f"https://github.com/circles-zone/{PACKAGE_NAME}-python-package",
|
|
@@ -19,8 +19,8 @@ setuptools.setup(
|
|
|
19
19
|
"License :: Other/Proprietary License",
|
|
20
20
|
"Operating System :: OS Independent",
|
|
21
21
|
],
|
|
22
|
-
install_requires=["database-mysql-local>=0.0.
|
|
23
|
-
"logger-local>=0.0.
|
|
22
|
+
install_requires=["database-mysql-local>=0.0.292",
|
|
23
|
+
"logger-local>=0.0.135",
|
|
24
24
|
"user-context-remote>=0.0.30",
|
|
25
25
|
]
|
|
26
26
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|