queue-local 0.0.48__tar.gz → 0.0.49__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.49}/PKG-INFO +3 -3
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local/src/database_queue.py +31 -45
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local.egg-info/PKG-INFO +3 -3
- queue_local-0.0.49/queue_local.egg-info/requires.txt +3 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/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.49}/README.md +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/pyproject.toml +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local/src/__init__.py +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local/src/our_queue.py +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/queue_local.egg-info/top_level.txt +0 -0
- {queue_local-0.0.48 → queue_local-0.0.49}/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.49
|
|
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,39 @@ 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
|
-
def push(self,
|
|
68
|
+
def push(self, data_dict: dict) -> int:
|
|
74
69
|
"""Pushes a new entry to the queue and returns the new queue id.
|
|
75
|
-
|
|
70
|
+
data_dict consists of columns and values to insert into the queue table."""
|
|
76
71
|
created_user_id = UserContext().get_effective_user_id()
|
|
77
72
|
|
|
78
|
-
self._fix_parameters_json(
|
|
73
|
+
self._fix_parameters_json(data_dict)
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
data_dict["queue_status_id"] = QueueStatusEnum.NEW.value
|
|
76
|
+
data_dict["created_user_id"] = created_user_id
|
|
82
77
|
|
|
83
|
-
if self.
|
|
84
|
-
|
|
85
|
-
del
|
|
86
|
-
self.
|
|
87
|
-
|
|
88
|
-
return id_column_value
|
|
78
|
+
if self.column_name in data_dict:
|
|
79
|
+
column_value = data_dict[self.column_name]
|
|
80
|
+
del data_dict[self.column_name]
|
|
81
|
+
self.update_by_column_and_value(column_value=column_value, data_dict=data_dict)
|
|
82
|
+
push_result = column_value
|
|
89
83
|
else:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
# TODO Can we do this everywhere?
|
|
84
|
+
push_result = self.insert(data_dict=data_dict)
|
|
85
|
+
return push_result
|
|
86
|
+
# TODO Can we do this everywhere? [I will make it auto in the meta logger]
|
|
93
87
|
# TODO logger.end("...", {'push_result': push_result} )
|
|
94
|
-
# TODO return push_result
|
|
95
88
|
|
|
96
89
|
def push_back(self, queue_item: dict) -> None:
|
|
97
90
|
"""Push a taken queue item back to the queue."""
|
|
98
|
-
|
|
99
|
-
self.
|
|
91
|
+
data_dict = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
|
|
92
|
+
self.update_by_column_and_value(column_value=queue_item[self.column_name], data_dict=data_dict)
|
|
100
93
|
|
|
101
94
|
def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
|
|
102
95
|
"""
|
|
@@ -106,29 +99,23 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
106
99
|
:param custom_condition: Custom condition to add to the WHERE clause (optional).
|
|
107
100
|
:return: Dictionary representing the retrieved queue item.
|
|
108
101
|
"""
|
|
109
|
-
updated_user_id = self.user_context.get_effective_user_id()
|
|
110
102
|
action_ids = self._fix_action_ids(action_ids)
|
|
111
103
|
|
|
112
|
-
|
|
104
|
+
data_dict = {"process_id": os.getpid()}
|
|
113
105
|
update_where = f"process_id IS NULL " \
|
|
114
106
|
f"AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value}) " \
|
|
115
107
|
f"AND NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
|
|
116
108
|
(f"AND action_id IN {action_ids} " if action_ids else "") + \
|
|
117
109
|
(f"AND {custom_condition}" if custom_condition else "")
|
|
118
|
-
self.update_by_where(where=update_where, order_by=self.
|
|
110
|
+
self.update_by_where(where=update_where, order_by=self.column_name, limit=1, data_dict=data_dict)
|
|
119
111
|
|
|
120
112
|
# TODO In which cases queue_status_id IS NULL? - Does it indicate a problem/bug?
|
|
121
113
|
select_where = f"process_id = {os.getpid()} AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})"
|
|
122
114
|
queue_item = self.select_one_dict_by_where(where=select_where)
|
|
123
115
|
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()
|
|
116
|
+
update_data_dict = {"queue_status_id": QueueStatusEnum.RETRIEVED.value,
|
|
117
|
+
"user_jwt": self.user_context.get_user_jwt()}
|
|
118
|
+
self.update_by_column_and_value(column_value=queue_item[self.column_name], data_dict=update_data_dict)
|
|
132
119
|
self.logger.info("Entry retrieved and updated from the queue database successfully",
|
|
133
120
|
object=queue_item)
|
|
134
121
|
else:
|
|
@@ -138,12 +125,11 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
138
125
|
def peek(self, action_ids: tuple = ()) -> dict:
|
|
139
126
|
"""Get the first item in the queue without changing it"""
|
|
140
127
|
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})" + \
|
|
128
|
+
where = f"process_id IS NULL AND queue_status_id = {QueueStatusEnum.NEW.value}" + \
|
|
143
129
|
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
144
130
|
# SELECT * FROM `queue`.`queue_item_view` WHERE process_id IS NULL AND queue_status_id = 0
|
|
145
131
|
# 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.
|
|
132
|
+
queue_item = self.select_one_dict_by_where(where=where, order_by=self.column_name)
|
|
147
133
|
return queue_item
|
|
148
134
|
|
|
149
135
|
def _fix_action_ids(self, action_ids):
|
|
@@ -158,11 +144,11 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
|
|
|
158
144
|
return action_ids if len(action_ids) != 1 else f"({action_ids[0]})"
|
|
159
145
|
|
|
160
146
|
@staticmethod
|
|
161
|
-
def _fix_parameters_json(
|
|
147
|
+
def _fix_parameters_json(data_dict: dict):
|
|
162
148
|
"""Fixes the parameters_json argument to fit the SQL syntax (parameters_json must be a string)"""
|
|
163
|
-
for key, value in
|
|
149
|
+
for key, value in data_dict.items():
|
|
164
150
|
if "parameters_json" in key:
|
|
165
151
|
if isinstance(value, str):
|
|
166
|
-
|
|
152
|
+
data_dict[key] = value.replace("'", '"')
|
|
167
153
|
else:
|
|
168
|
-
|
|
154
|
+
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.49
|
|
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.49',
|
|
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
|