queue-local 0.0.39__tar.gz → 0.0.41__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.39 → queue-local-0.0.41}/PKG-INFO +3 -4
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local/src/database_queue.py +47 -67
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local/src/our_queue.py +2 -4
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local.egg-info/PKG-INFO +3 -4
- queue-local-0.0.41/queue_local.egg-info/requires.txt +3 -0
- {queue-local-0.0.39 → queue-local-0.0.41}/setup.py +3 -4
- queue-local-0.0.39/queue_local.egg-info/requires.txt +0 -4
- {queue-local-0.0.39 → queue-local-0.0.41}/README.md +0 -0
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local/src/__init__.py +0 -0
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local.egg-info/SOURCES.txt +0 -0
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local.egg-info/dependency_links.txt +0 -0
- {queue-local-0.0.39 → queue-local-0.0.41}/queue_local.egg-info/top_level.txt +0 -0
- {queue-local-0.0.39 → queue-local-0.0.41}/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.41
|
|
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,9 +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:
|
|
12
|
-
Requires-Dist:
|
|
13
|
-
Requires-Dist: logger-local>=0.0.59
|
|
11
|
+
Requires-Dist: database-mysql-local>=0.0.212
|
|
12
|
+
Requires-Dist: logger-local>=0.0.101
|
|
14
13
|
Requires-Dist: user-context-remote>=0.0.30
|
|
15
14
|
|
|
16
15
|
queue-local
|
|
@@ -3,10 +3,9 @@ import os
|
|
|
3
3
|
from collections.abc import Iterable
|
|
4
4
|
from enum import Enum
|
|
5
5
|
|
|
6
|
-
import mysql.connector
|
|
7
6
|
from database_mysql_local.generic_crud import GenericCRUD
|
|
8
7
|
from logger_local.LoggerComponentEnum import LoggerComponentEnum
|
|
9
|
-
from logger_local.
|
|
8
|
+
from logger_local.MetaLogger import MetaLogger
|
|
10
9
|
from user_context_remote.user_context import UserContext
|
|
11
10
|
|
|
12
11
|
from .our_queue import OurQueue
|
|
@@ -14,6 +13,12 @@ from .our_queue import OurQueue
|
|
|
14
13
|
QUEUE_LOCAL_PYTHON_COMPONENT_ID = 155
|
|
15
14
|
QUEUE_LOCAL_PYTHON_COMPONENT_NAME = "queue_local/src/database_queue.py"
|
|
16
15
|
DEVELOPER_EMAIL = 'akiva.s@circ.zone'
|
|
16
|
+
queue_logger_object = {
|
|
17
|
+
'component_id': QUEUE_LOCAL_PYTHON_COMPONENT_ID,
|
|
18
|
+
'component_name': QUEUE_LOCAL_PYTHON_COMPONENT_NAME,
|
|
19
|
+
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
20
|
+
'developer_email': DEVELOPER_EMAIL
|
|
21
|
+
}
|
|
17
22
|
|
|
18
23
|
|
|
19
24
|
class StatusEnum(Enum):
|
|
@@ -21,16 +26,17 @@ class StatusEnum(Enum):
|
|
|
21
26
|
RETRIEVED = 1
|
|
22
27
|
|
|
23
28
|
|
|
24
|
-
class DatabaseQueue(OurQueue, GenericCRUD):
|
|
29
|
+
class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_logger_object):
|
|
25
30
|
"""A queue that uses a database table as the queue."""
|
|
26
31
|
|
|
27
32
|
def __init__(self, schema_name: str = "queue", table_name: str = "queue_item_table",
|
|
28
|
-
view_name: str = "queue_item_view", id_column_name: str = "queue_item_id"
|
|
33
|
+
view_name: str = "queue_item_view", id_column_name: str = "queue_item_id",
|
|
34
|
+
is_test_data: bool = False) -> None:
|
|
29
35
|
"""Initialize the queue.
|
|
30
36
|
Make sure the table has the following columns:
|
|
31
37
|
queue_status_id, action_id, process_id, user_jwt
|
|
32
38
|
created_user_id, updated_user_id
|
|
33
|
-
|
|
39
|
+
updated_timestamp, start_timestamp, end_timestamp
|
|
34
40
|
|
|
35
41
|
ALTER TABLE `invitation`.`invitation_table`
|
|
36
42
|
ADD COLUMN `queue_status_id` SMALLINT UNSIGNED NULL AFTER `updated_effective_profile_id`,
|
|
@@ -44,14 +50,9 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
44
50
|
(or "_view" added to the end if there is no "_table").
|
|
45
51
|
You can pass a Connector object to use an existing connection, or None to create a new connection.
|
|
46
52
|
"""
|
|
47
|
-
self.logger =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'component_name': QUEUE_LOCAL_PYTHON_COMPONENT_NAME,
|
|
51
|
-
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
52
|
-
'developer_email': DEVELOPER_EMAIL
|
|
53
|
-
}
|
|
54
|
-
)
|
|
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})
|
|
55
56
|
if not view_name:
|
|
56
57
|
if table_name.endswith("_table"):
|
|
57
58
|
view_name = table_name.replace("_table", "_view")
|
|
@@ -62,37 +63,29 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
62
63
|
self.id_column_name = id_column_name
|
|
63
64
|
|
|
64
65
|
GenericCRUD.__init__(self, default_schema_name=schema_name, default_table_name=table_name,
|
|
65
|
-
default_view_table_name=view_name, default_id_column_name=id_column_name
|
|
66
|
-
|
|
66
|
+
default_view_table_name=view_name, default_id_column_name=id_column_name,
|
|
67
|
+
is_test_data=is_test_data)
|
|
68
|
+
self.user_context = UserContext().login_using_user_identification_and_password()
|
|
69
|
+
self.logger.end("DatabaseQueue initialized successfully", object={
|
|
67
70
|
"schema_name": schema_name, "table_name": table_name,
|
|
68
71
|
"view_name": view_name, "id_column_name": id_column_name})
|
|
69
|
-
self.user = UserContext()
|
|
70
72
|
|
|
71
73
|
def push(self, data_json: dict) -> int:
|
|
72
|
-
"""Pushes a new entry to the queue.
|
|
74
|
+
"""Pushes a new entry to the queue and returns the new queue id.
|
|
73
75
|
data_json consists of columns and values to insert into the queue table."""
|
|
74
76
|
created_user_id = UserContext().get_effective_user_id()
|
|
75
|
-
self.logger.start("Pushing entry to the queue database", object={"data_json": data_json})
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
self._fix_parameters_json(data_json)
|
|
78
|
+
self._fix_parameters_json(data_json)
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
data_json["queue_status_id"] = StatusEnum.NEW.value
|
|
81
|
+
data_json["created_user_id"] = created_user_id
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
self.logger.end("Entry pushed to the queue database successfully")
|
|
85
|
-
except Exception as e:
|
|
86
|
-
self.logger.exception("Error while pushing entry to the queue database", object=e)
|
|
87
|
-
raise
|
|
88
|
-
return queue_id
|
|
83
|
+
return self.insert(data_json=data_json)
|
|
89
84
|
|
|
90
85
|
def push_back(self, queue_item: dict) -> None:
|
|
91
86
|
"""Push a taken queue item back to the queue."""
|
|
92
|
-
self.logger.start("Pushing back queue item", object=queue_item)
|
|
93
87
|
data_json = {"queue_status_id": StatusEnum.NEW.value, "process_id": None}
|
|
94
88
|
self.update_by_id(id_column_value=queue_item[self.id_column_name], data_json=data_json)
|
|
95
|
-
self.logger.end("Queue item pushed back successfully")
|
|
96
89
|
|
|
97
90
|
def get(self, action_ids: tuple = ()) -> dict:
|
|
98
91
|
"""
|
|
@@ -101,36 +94,30 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
101
94
|
:param action_ids: Tuple of action IDs to consider (optional).
|
|
102
95
|
:return: Dictionary representing the retrieved queue item.
|
|
103
96
|
"""
|
|
104
|
-
updated_user_id = self.
|
|
105
|
-
self.logger.start("Getting and updating queue item from the queue database", object={"action_ids": action_ids})
|
|
97
|
+
updated_user_id = self.user_context.get_effective_user_id()
|
|
106
98
|
action_ids = self._fix_action_ids(action_ids)
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
self.logger.end("The queue is empty")
|
|
130
|
-
except mysql.connector.Error as e:
|
|
131
|
-
self.connection.rollback()
|
|
132
|
-
self.logger.exception("Error while getting and updating queue item from the queue database", object=e)
|
|
133
|
-
raise
|
|
100
|
+
data_json = {"process_id": os.getpid()}
|
|
101
|
+
update_where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value} AND " \
|
|
102
|
+
f"NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp)" + \
|
|
103
|
+
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
104
|
+
self.update_by_where(where=update_where, order_by=self.id_column_name, limit=1, data_json=data_json)
|
|
105
|
+
|
|
106
|
+
select_where = f"process_id = {os.getpid()} AND queue_status_id = {StatusEnum.NEW.value}"
|
|
107
|
+
queue_item = self.select_one_dict_by_where(where=select_where)
|
|
108
|
+
if queue_item:
|
|
109
|
+
# Update the selected queue item
|
|
110
|
+
query = f"UPDATE {self.schema_name}.{self.default_table_name} " \
|
|
111
|
+
f"SET queue_status_id=%s, updated_user_id=%s, user_jwt=%s, updated_timestamp = NOW() " \
|
|
112
|
+
f"WHERE {self.id_column_name} = %s"
|
|
113
|
+
params = (StatusEnum.RETRIEVED.value, updated_user_id, self.user_context.get_user_jwt(),
|
|
114
|
+
queue_item[self.id_column_name])
|
|
115
|
+
self.cursor.execute(query, params)
|
|
116
|
+
self.connection.commit()
|
|
117
|
+
self.logger.info("Entry retrieved and updated from the queue database successfully",
|
|
118
|
+
object=queue_item)
|
|
119
|
+
else:
|
|
120
|
+
self.logger.info("The queue is empty")
|
|
134
121
|
return queue_item
|
|
135
122
|
|
|
136
123
|
def peek(self, action_ids: tuple = ()) -> dict:
|
|
@@ -138,14 +125,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
138
125
|
action_ids = self._fix_action_ids(action_ids)
|
|
139
126
|
where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value}" + \
|
|
140
127
|
(f" AND action_id IN {action_ids}" if action_ids else "")
|
|
141
|
-
|
|
142
|
-
self.logger.start("Peeking queue item from the queue database")
|
|
143
|
-
queue_item = self.select_one_dict_by_where(where=where, order_by="created_timestamp")
|
|
144
|
-
self.logger.end("Entry peeked from the queue database successfully" if queue_item else "The queue is empty")
|
|
145
|
-
except Exception as e:
|
|
146
|
-
self.logger.exception("Error while peeking queue item from the queue database", object=e)
|
|
147
|
-
raise
|
|
148
|
-
return queue_item
|
|
128
|
+
return self.select_one_dict_by_where(where=where, order_by=self.id_column_name)
|
|
149
129
|
|
|
150
130
|
def _fix_action_ids(self, action_ids):
|
|
151
131
|
"""Fixes the action_ids argument to fit the SQL syntax (action_id IN action_ids)"""
|
|
@@ -155,7 +135,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
|
|
|
155
135
|
action_ids = tuple(action_ids)
|
|
156
136
|
else:
|
|
157
137
|
self.logger.error("get_by_action_ids (queue database) invalid argument", object={"action_ids": action_ids})
|
|
158
|
-
raise ValueError("`action_ids` must be a tuple")
|
|
138
|
+
raise ValueError(f"`action_ids` must be a tuple, not `{action_ids}`")
|
|
159
139
|
return action_ids if len(action_ids) != 1 else f"({action_ids[0]})"
|
|
160
140
|
|
|
161
141
|
@staticmethod
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
1
|
from abc import ABC, abstractmethod
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
from logger_local.MetaLogger import ABCMetaLogger
|
|
6
4
|
|
|
7
5
|
|
|
8
|
-
class OurQueue(ABC):
|
|
6
|
+
class OurQueue(ABC, metaclass=ABCMetaLogger):
|
|
9
7
|
|
|
10
8
|
@abstractmethod
|
|
11
9
|
def push(self, item):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: queue-local
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.41
|
|
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,9 +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:
|
|
12
|
-
Requires-Dist:
|
|
13
|
-
Requires-Dist: logger-local>=0.0.59
|
|
11
|
+
Requires-Dist: database-mysql-local>=0.0.212
|
|
12
|
+
Requires-Dist: logger-local>=0.0.101
|
|
14
13
|
Requires-Dist: user-context-remote>=0.0.30
|
|
15
14
|
|
|
16
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.41',
|
|
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,9 +19,8 @@ setuptools.setup(
|
|
|
19
19
|
"License :: Other/Proprietary License",
|
|
20
20
|
"Operating System :: OS Independent",
|
|
21
21
|
],
|
|
22
|
-
install_requires=["
|
|
23
|
-
"
|
|
24
|
-
"logger-local>=0.0.59",
|
|
22
|
+
install_requires=["database-mysql-local>=0.0.212",
|
|
23
|
+
"logger-local>=0.0.101",
|
|
25
24
|
"user-context-remote>=0.0.30",
|
|
26
25
|
]
|
|
27
26
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|