queue-local 0.0.40__tar.gz → 0.0.42__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: queue-local
3
- Version: 0.0.40
3
+ Version: 0.0.42
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.120
12
- Requires-Dist: logger-local>=0.0.59
11
+ Requires-Dist: database-mysql-local>=0.0.212
12
+ Requires-Dist: logger-local>=0.0.101
13
13
  Requires-Dist: user-context-remote>=0.0.30
14
14
 
15
15
  queue-local
@@ -0,0 +1,14 @@
1
+ # This file should be in the future instead of setup.py
2
+ # https://python-poetry.org/docs/pyproject
3
+ [build-system]
4
+ requires = ["setuptools>=61.0"]
5
+ build-backend = "setuptools.build_meta"
6
+
7
+ [tool.poetry]
8
+ name = "queue-local"
9
+ version = "0.0.1" # https://pypi.org/project/queue-local
10
+ description = "queue-local Python Package"
11
+ readme = "README.md"
12
+ authors = [
13
+ "Circlez.ai <info@circlez.ai>",
14
+ ]
@@ -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.LoggerLocal import Logger
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,7 +26,7 @@ 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",
@@ -31,7 +36,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
31
36
  Make sure the table has the following columns:
32
37
  queue_status_id, action_id, process_id, user_jwt
33
38
  created_user_id, updated_user_id
34
- created_timestamp, updated_timestamp, start_timestamp, end_timestamp
39
+ updated_timestamp, start_timestamp, end_timestamp
35
40
 
36
41
  ALTER TABLE `invitation`.`invitation_table`
37
42
  ADD COLUMN `queue_status_id` SMALLINT UNSIGNED NULL AFTER `updated_effective_profile_id`,
@@ -45,14 +50,9 @@ class DatabaseQueue(OurQueue, GenericCRUD):
45
50
  (or "_view" added to the end if there is no "_table").
46
51
  You can pass a Connector object to use an existing connection, or None to create a new connection.
47
52
  """
48
- self.logger = Logger(
49
- object={
50
- 'component_id': QUEUE_LOCAL_PYTHON_COMPONENT_ID,
51
- 'component_name': QUEUE_LOCAL_PYTHON_COMPONENT_NAME,
52
- 'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
53
- 'developer_email': DEVELOPER_EMAIL
54
- }
55
- )
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
56
  if not view_name:
57
57
  if table_name.endswith("_table"):
58
58
  view_name = table_name.replace("_table", "_view")
@@ -65,36 +65,27 @@ class DatabaseQueue(OurQueue, GenericCRUD):
65
65
  GenericCRUD.__init__(self, default_schema_name=schema_name, default_table_name=table_name,
66
66
  default_view_table_name=view_name, default_id_column_name=id_column_name,
67
67
  is_test_data=is_test_data)
68
- self.logger.info("DatabaseQueue initialized successfully", object={
68
+ self.user_context = UserContext().login_using_user_identification_and_password()
69
+ self.logger.end("DatabaseQueue initialized successfully", object={
69
70
  "schema_name": schema_name, "table_name": table_name,
70
71
  "view_name": view_name, "id_column_name": id_column_name})
71
- self.user_context = UserContext().login_using_user_identification_and_password()
72
72
 
73
73
  def push(self, data_json: dict) -> int:
74
- """Pushes a new entry to the queue.
74
+ """Pushes a new entry to the queue and returns the new queue id.
75
75
  data_json consists of columns and values to insert into the queue table."""
76
76
  created_user_id = UserContext().get_effective_user_id()
77
- self.logger.start("Pushing entry to the queue database", object={"data_json": data_json})
78
77
 
79
- try:
80
- self._fix_parameters_json(data_json)
78
+ self._fix_parameters_json(data_json)
81
79
 
82
- data_json["queue_status_id"] = StatusEnum.NEW.value
83
- data_json["created_user_id"] = created_user_id
80
+ data_json["queue_status_id"] = StatusEnum.NEW.value
81
+ data_json["created_user_id"] = created_user_id
84
82
 
85
- queue_id = self.insert(data_json=data_json) # returning the queue_id for messages-local
86
- self.logger.end("Entry pushed to the queue database successfully")
87
- except Exception as exception:
88
- self.logger.error("Error while pushing entry to the queue database", object=exception)
89
- raise exception
90
- return queue_id
83
+ return self.insert(data_json=data_json)
91
84
 
92
85
  def push_back(self, queue_item: dict) -> None:
93
86
  """Push a taken queue item back to the queue."""
94
- self.logger.start("Pushing back queue item", object=queue_item)
95
87
  data_json = {"queue_status_id": StatusEnum.NEW.value, "process_id": None}
96
88
  self.update_by_id(id_column_value=queue_item[self.id_column_name], data_json=data_json)
97
- self.logger.end("Queue item pushed back successfully")
98
89
 
99
90
  def get(self, action_ids: tuple = ()) -> dict:
100
91
  """
@@ -104,36 +95,29 @@ class DatabaseQueue(OurQueue, GenericCRUD):
104
95
  :return: Dictionary representing the retrieved queue item.
105
96
  """
106
97
  updated_user_id = self.user_context.get_effective_user_id()
107
- self.logger.start("Getting and updating queue item from the queue database", object={"action_ids": action_ids})
108
98
  action_ids = self._fix_action_ids(action_ids)
109
99
 
110
- try:
111
- data_json = {"process_id": os.getpid()}
112
- update_where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value} AND " \
113
- f"NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp)" + \
114
- (f" AND action_id IN {action_ids}" if action_ids else "")
115
- self.update_by_where(where=update_where, order_by="created_timestamp", limit=1, data_json=data_json)
116
-
117
- select_where = f"process_id = {os.getpid()} AND queue_status_id = {StatusEnum.NEW.value}"
118
- queue_item = self.select_one_dict_by_where(where=select_where)
119
- if queue_item:
120
- # Update the selected queue item
121
- query = f"UPDATE {self.schema_name}.{self.default_table_name} " \
122
- f"SET queue_status_id=%s, updated_user_id=%s, user_jwt=%s, updated_timestamp = NOW() " \
123
- f"WHERE {self.id_column_name} = %s"
124
- params = (StatusEnum.RETRIEVED.value, updated_user_id, self.user_context.get_user_jwt(),
125
- queue_item[self.id_column_name])
126
- self.cursor.execute(query, params)
127
- self.connection.commit()
128
- self.logger.end("Entry retrieved and updated from the queue database successfully",
129
- object=queue_item)
130
- else:
131
- self.logger.end("The queue is empty")
132
- except mysql.connector.Error as exception:
133
- self.connection.rollback()
134
- self.logger.error("Error while getting and updating queue item from the queue database",
135
- object=exception)
136
- raise exception
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")
137
121
  return queue_item
138
122
 
139
123
  def peek(self, action_ids: tuple = ()) -> dict:
@@ -141,14 +125,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
141
125
  action_ids = self._fix_action_ids(action_ids)
142
126
  where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value}" + \
143
127
  (f" AND action_id IN {action_ids}" if action_ids else "")
144
- try:
145
- self.logger.start("Peeking queue item from the queue database")
146
- queue_item = self.select_one_dict_by_where(where=where, order_by="created_timestamp")
147
- self.logger.end("Entry peeked from the queue database successfully" if queue_item else "The queue is empty")
148
- except Exception as e:
149
- self.logger.exception("Error while peeking queue item from the queue database", object=e)
150
- raise
151
- return queue_item
128
+ return self.select_one_dict_by_where(where=where, order_by=self.id_column_name)
152
129
 
153
130
  def _fix_action_ids(self, action_ids):
154
131
  """Fixes the action_ids argument to fit the SQL syntax (action_id IN action_ids)"""
@@ -158,7 +135,7 @@ class DatabaseQueue(OurQueue, GenericCRUD):
158
135
  action_ids = tuple(action_ids)
159
136
  else:
160
137
  self.logger.error("get_by_action_ids (queue database) invalid argument", object={"action_ids": action_ids})
161
- raise ValueError("`action_ids` must be a tuple")
138
+ raise ValueError(f"`action_ids` must be a tuple, not `{action_ids}`")
162
139
  return action_ids if len(action_ids) != 1 else f"({action_ids[0]})"
163
140
 
164
141
  @staticmethod
@@ -1,7 +1,9 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
+ from logger_local.MetaLogger import ABCMetaLogger
3
4
 
4
- class OurQueue(ABC):
5
+
6
+ class OurQueue(ABC, metaclass=ABCMetaLogger):
5
7
 
6
8
  @abstractmethod
7
9
  def push(self, item):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: queue-local
3
- Version: 0.0.40
3
+ Version: 0.0.42
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.120
12
- Requires-Dist: logger-local>=0.0.59
11
+ Requires-Dist: database-mysql-local>=0.0.212
12
+ Requires-Dist: logger-local>=0.0.101
13
13
  Requires-Dist: user-context-remote>=0.0.30
14
14
 
15
15
  queue-local
@@ -1,4 +1,5 @@
1
1
  README.md
2
+ pyproject.toml
2
3
  setup.py
3
4
  queue_local.egg-info/PKG-INFO
4
5
  queue_local.egg-info/SOURCES.txt
@@ -0,0 +1,3 @@
1
+ database-mysql-local>=0.0.212
2
+ logger-local>=0.0.101
3
+ user-context-remote>=0.0.30
@@ -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.40',
8
+ version='0.0.42',
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.120",
23
- "logger-local>=0.0.59",
22
+ install_requires=["database-mysql-local>=0.0.212",
23
+ "logger-local>=0.0.101",
24
24
  "user-context-remote>=0.0.30",
25
25
  ]
26
26
  )
@@ -1,3 +0,0 @@
1
- database-mysql-local>=0.0.120
2
- logger-local>=0.0.59
3
- user-context-remote>=0.0.30
File without changes
File without changes