queue-local 0.0.32__tar.gz → 0.0.39__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.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: queue-local
3
+ Version: 0.0.39
4
+ Home-page: https://github.com/circles-zone/queue-local-python-package
5
+ Author: Circles
6
+ Author-email: info@circles.life
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: Other/Proprietary License
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: pytest>=7.4.1
12
+ Requires-Dist: database-mysql-local>=0.0.120
13
+ Requires-Dist: logger-local>=0.0.59
14
+ Requires-Dist: user-context-remote>=0.0.30
15
+
16
+ queue-local
@@ -3,11 +3,13 @@
3
3
  ## Usage:
4
4
 
5
5
  Install:
6
+
6
7
  ```bash
7
8
  pip install queue-local
8
9
  ```
9
- - It's recommended to add `queue-local` to your `requirements.txt` file if you're using it as part of your project dependencies.
10
10
 
11
+ - It's recommended to add `queue-local` to your `requirements.txt` file if you're using it as part of your project
12
+ dependencies.
11
13
 
12
14
  ### Using the `DatabaseQueue` Class:
13
15
 
@@ -24,7 +26,7 @@ q.push({"item_description": "test 2", "action_id": 2, "parameters_json": {'a': 1
24
26
  result1 = q.peek() # "test 1" is still in the queue
25
27
 
26
28
  # Get an item from the queue (and remove it) based on action_id
27
- result2 = q.get(action_ids=(2, )) # Gets "test 2" (the first item with action_id=2)
29
+ result2 = q.get(action_ids=(2,)) # Gets "test 2" (the first item with action_id=2)
28
30
 
29
31
  # Get an item from the queue (and remove it)
30
32
  result3 = q.get() # Gets "test 1"
@@ -32,17 +34,16 @@ result3 = q.get() # Gets "test 1"
32
34
  q.close() # close the database connection
33
35
  ```
34
36
 
35
-
36
-
37
37
  ### Inheriting from the Abstract `OurQueue` Class:
38
38
 
39
39
  ```py
40
40
  from queue_local.our_queue import OurQueue
41
41
 
42
+
42
43
  class YourCustomQueue(OurQueue):
43
44
  def __init__(self):
44
45
  pass
45
-
46
+
46
47
  def push(self, item):
47
48
  """Push an item to the queue"""
48
49
  pass
@@ -1,15 +1,12 @@
1
1
  import json
2
2
  import os
3
- import threading
4
3
  from collections.abc import Iterable
5
4
  from enum import Enum
6
5
 
7
6
  import mysql.connector
8
- import requests
9
- from circles_local_database_python.connector import Connector
10
- from circles_local_database_python.generic_crud import GenericCRUD
11
- from logger_local.Logger import Logger
7
+ from database_mysql_local.generic_crud import GenericCRUD
12
8
  from logger_local.LoggerComponentEnum import LoggerComponentEnum
9
+ from logger_local.LoggerLocal import Logger
13
10
  from user_context_remote.user_context import UserContext
14
11
 
15
12
  from .our_queue import OurQueue
@@ -18,9 +15,6 @@ QUEUE_LOCAL_PYTHON_COMPONENT_ID = 155
18
15
  QUEUE_LOCAL_PYTHON_COMPONENT_NAME = "queue_local/src/database_queue.py"
19
16
  DEVELOPER_EMAIL = 'akiva.s@circ.zone'
20
17
 
21
- ip_v4 = requests.get('https://ipv4.seeip.org/jsonip').json()['ip']
22
- ip_v6 = requests.get('https://api.seeip.org/jsonip').json()['ip']
23
-
24
18
 
25
19
  class StatusEnum(Enum):
26
20
  NEW = 0
@@ -29,11 +23,25 @@ class StatusEnum(Enum):
29
23
 
30
24
  class DatabaseQueue(OurQueue, GenericCRUD):
31
25
  """A queue that uses a database table as the queue."""
32
- def __init__(self, schema_name: str = "queue", table_name: str = "queue_item_table", view_name: str = "queue_item_view",
33
- id_column_name: str = "queue_item_id", connection: Connector = None) -> None:
26
+
27
+ 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") -> None:
34
29
  """Initialize the queue.
30
+ Make sure the table has the following columns:
31
+ queue_status_id, action_id, process_id, user_jwt
32
+ created_user_id, updated_user_id
33
+ created_timestamp, updated_timestamp, start_timestamp, end_timestamp
34
+
35
+ ALTER TABLE `invitation`.`invitation_table`
36
+ ADD COLUMN `queue_status_id` SMALLINT UNSIGNED NULL AFTER `updated_effective_profile_id`,
37
+ ADD COLUMN `action_id` SMALLINT UNSIGNED NULL AFTER `queue_status_id`,
38
+ ADD COLUMN `process_id` MEDIUMINT UNSIGNED NULL AFTER `action_id`,
39
+ ADD COLUMN `user_jwt` VARCHAR(255) NULL AFTER `process_id`;
40
+
41
+
35
42
  Default schema_name = the first part of the table_name, before the first underscore.
36
- Default view_name = table_name with "_view" instead of "_table" (or "_view" added to the end if there is no "_table").
43
+ Default view_name = table_name with "_view" instead of "_table"
44
+ (or "_view" added to the end if there is no "_table").
37
45
  You can pass a Connector object to use an existing connection, or None to create a new connection.
38
46
  """
39
47
  self.logger = Logger(
@@ -53,13 +61,14 @@ class DatabaseQueue(OurQueue, GenericCRUD):
53
61
  schema_name = table_name.split("_")[0]
54
62
  self.id_column_name = id_column_name
55
63
 
56
- GenericCRUD.__init__(self, default_schema_name=schema_name, default_table_name=table_name, default_view_table_name=view_name,
57
- default_id_column_name=id_column_name, connection=connection)
64
+ 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)
58
66
  self.logger.info("DatabaseQueue initialized successfully", object={
59
- "schema_name": schema_name, "table_name": table_name, "view_name": view_name, "id_column_name": id_column_name})
67
+ "schema_name": schema_name, "table_name": table_name,
68
+ "view_name": view_name, "id_column_name": id_column_name})
60
69
  self.user = UserContext()
61
70
 
62
- def push(self, data_json: dict) -> None:
71
+ def push(self, data_json: dict) -> int:
63
72
  """Pushes a new entry to the queue.
64
73
  data_json consists of columns and values to insert into the queue table."""
65
74
  created_user_id = UserContext().get_effective_user_id()
@@ -71,11 +80,12 @@ class DatabaseQueue(OurQueue, GenericCRUD):
71
80
  data_json["queue_status_id"] = StatusEnum.NEW.value
72
81
  data_json["created_user_id"] = created_user_id
73
82
 
74
- self.insert(data_json=data_json)
83
+ queue_id = self.insert(data_json=data_json) # returning the queue_id for messages-local
75
84
  self.logger.end("Entry pushed to the queue database successfully")
76
85
  except Exception as e:
77
86
  self.logger.exception("Error while pushing entry to the queue database", object=e)
78
87
  raise
88
+ return queue_id
79
89
 
80
90
  def push_back(self, queue_item: dict) -> None:
81
91
  """Push a taken queue item back to the queue."""
@@ -97,7 +107,8 @@ class DatabaseQueue(OurQueue, GenericCRUD):
97
107
 
98
108
  try:
99
109
  data_json = {"process_id": os.getpid()}
100
- update_where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value}" + \
110
+ update_where = f"process_id IS NULL AND queue_status_id = {StatusEnum.NEW.value} AND " \
111
+ f"NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp)" + \
101
112
  (f" AND action_id IN {action_ids}" if action_ids else "")
102
113
  self.update_by_where(where=update_where, order_by="created_timestamp", limit=1, data_json=data_json)
103
114
 
@@ -105,12 +116,11 @@ class DatabaseQueue(OurQueue, GenericCRUD):
105
116
  queue_item = self.select_one_dict_by_where(where=select_where)
106
117
  if queue_item:
107
118
  # Update the selected queue item
108
- query = f"UPDATE {self.default_table_name} " \
109
- f"SET queue_status_id=%s, updated_user_id=%s, user_jwt=%s, thread_id=%s," \
110
- f"server_ip_v4=%s, server_ip_v6=%s, start_timestamp = NOW() " \
119
+ query = f"UPDATE {self.schema_name}.{self.default_table_name} " \
120
+ f"SET queue_status_id=%s, updated_user_id=%s, user_jwt=%s, updated_timestamp = NOW() " \
111
121
  f"WHERE {self.id_column_name} = %s"
112
- params = (StatusEnum.RETRIEVED.value, updated_user_id, self.user.get_user_JWT(),
113
- get_thread_id(), ip_v4, ip_v6, queue_item[self.id_column_name])
122
+ params = (StatusEnum.RETRIEVED.value, updated_user_id, self.user.get_user_jwt(),
123
+ queue_item[self.id_column_name])
114
124
  self.cursor.execute(query, params)
115
125
  self.connection.commit()
116
126
  self.logger.end("Entry retrieved and updated from the queue database successfully",
@@ -157,8 +167,3 @@ class DatabaseQueue(OurQueue, GenericCRUD):
157
167
  data_json[key] = value.replace("'", '"')
158
168
  else:
159
169
  data_json[key] = json.dumps(value)
160
-
161
-
162
- def get_thread_id():
163
- """Returns the current thread ID"""
164
- return threading.current_thread().ident
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: queue-local
3
+ Version: 0.0.39
4
+ Home-page: https://github.com/circles-zone/queue-local-python-package
5
+ Author: Circles
6
+ Author-email: info@circles.life
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: Other/Proprietary License
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: pytest>=7.4.1
12
+ Requires-Dist: database-mysql-local>=0.0.120
13
+ Requires-Dist: logger-local>=0.0.59
14
+ Requires-Dist: user-context-remote>=0.0.30
15
+
16
+ queue-local
@@ -1,5 +1,4 @@
1
1
  README.md
2
- pyproject.toml
3
2
  setup.py
4
3
  queue_local.egg-info/PKG-INFO
5
4
  queue_local.egg-info/SOURCES.txt
@@ -1,6 +1,4 @@
1
- mysql-connector>=2.2.9
2
1
  pytest>=7.4.1
3
2
  database-mysql-local>=0.0.120
4
3
  logger-local>=0.0.59
5
4
  user-context-remote>=0.0.30
6
- requests>=2.22.0
@@ -3,30 +3,25 @@ import setuptools
3
3
  PACKAGE_NAME = "queue-local"
4
4
  package_dir = PACKAGE_NAME.replace("-", "_")
5
5
 
6
- with open('README.md') as f:
7
- readme = f.read()
8
-
9
6
  setuptools.setup(
10
7
  name=PACKAGE_NAME, # https://pypi.org/project/queue-local
11
- version='0.0.32',
8
+ version='0.0.39',
12
9
  author="Circles",
13
10
  author_email="info@circles.life",
14
11
  url=f"https://github.com/circles-zone/{PACKAGE_NAME}-python-package",
15
12
  packages=[package_dir],
16
13
  package_dir={package_dir: f'{package_dir}/src'},
17
14
  package_data={package_dir: ['*.py']},
18
- long_description=readme,
15
+ long_description="queue-local",
19
16
  long_description_content_type='text/markdown',
20
17
  classifiers=[
21
18
  "Programming Language :: Python :: 3",
22
19
  "License :: Other/Proprietary License",
23
20
  "Operating System :: OS Independent",
24
21
  ],
25
- install_requires=["mysql-connector>=2.2.9",
26
- "pytest>=7.4.1",
22
+ install_requires=["pytest>=7.4.1",
27
23
  "database-mysql-local>=0.0.120",
28
24
  "logger-local>=0.0.59",
29
25
  "user-context-remote>=0.0.30",
30
- "requests>=2.22.0",
31
26
  ]
32
27
  )
@@ -1,75 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: queue-local
3
- Version: 0.0.32
4
- Home-page: https://github.com/circles-zone/queue-local-python-package
5
- Author: Circles
6
- Author-email: info@circles.life
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: Other/Proprietary License
9
- Classifier: Operating System :: OS Independent
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: mysql-connector>=2.2.9
12
- Requires-Dist: pytest>=7.4.1
13
- Requires-Dist: database-mysql-local>=0.0.120
14
- Requires-Dist: logger-local>=0.0.59
15
- Requires-Dist: user-context-remote>=0.0.30
16
- Requires-Dist: requests>=2.22.0
17
-
18
- # queue-local-python-package
19
-
20
- ## Usage:
21
-
22
- Install:
23
- ```bash
24
- pip install queue-local
25
- ```
26
- - It's recommended to add `queue-local` to your `requirements.txt` file if you're using it as part of your project dependencies.
27
-
28
-
29
- ### Using the `DatabaseQueue` Class:
30
-
31
- ```py
32
- from queue_local.database_queue import DatabaseQueue
33
-
34
- q = DatabaseQueue() # you can also pass some parameters here, see the class definition for more info
35
-
36
- # Push items into the queue
37
- q.push({"item_description": "test 1", "action_id": 1, "parameters_json": "{'a': 1, 'b': 2}"})
38
- q.push({"item_description": "test 2", "action_id": 2, "parameters_json": {'a': 1, 'b': 2}})
39
-
40
- # Peek at the first item in the queue (without removing it)
41
- result1 = q.peek() # "test 1" is still in the queue
42
-
43
- # Get an item from the queue (and remove it) based on action_id
44
- result2 = q.get(action_ids=(2, )) # Gets "test 2" (the first item with action_id=2)
45
-
46
- # Get an item from the queue (and remove it)
47
- result3 = q.get() # Gets "test 1"
48
-
49
- q.close() # close the database connection
50
- ```
51
-
52
-
53
-
54
- ### Inheriting from the Abstract `OurQueue` Class:
55
-
56
- ```py
57
- from queue_local.our_queue import OurQueue
58
-
59
- class YourCustomQueue(OurQueue):
60
- def __init__(self):
61
- pass
62
-
63
- def push(self, item):
64
- """Push an item to the queue"""
65
- pass
66
-
67
- def get(self):
68
- """Get an item from the queue (and delete)"""
69
- pass
70
-
71
- def peek(self):
72
- """Peek at the head of the queue (without deleting)"""
73
- pass
74
- # Add any additional functions you need, such as is_empty()
75
- ```
@@ -1,14 +0,0 @@
1
- # https://python-poetry.org/docs/pyproject
2
-
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.26"
10
- description = "Queue Local Python Package"
11
- readme = "README.md"
12
- authors = [
13
- "Circlez.ai <info@circlez.ai>",
14
- ]
@@ -1,75 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: queue-local
3
- Version: 0.0.32
4
- Home-page: https://github.com/circles-zone/queue-local-python-package
5
- Author: Circles
6
- Author-email: info@circles.life
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: Other/Proprietary License
9
- Classifier: Operating System :: OS Independent
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: mysql-connector>=2.2.9
12
- Requires-Dist: pytest>=7.4.1
13
- Requires-Dist: database-mysql-local>=0.0.120
14
- Requires-Dist: logger-local>=0.0.59
15
- Requires-Dist: user-context-remote>=0.0.30
16
- Requires-Dist: requests>=2.22.0
17
-
18
- # queue-local-python-package
19
-
20
- ## Usage:
21
-
22
- Install:
23
- ```bash
24
- pip install queue-local
25
- ```
26
- - It's recommended to add `queue-local` to your `requirements.txt` file if you're using it as part of your project dependencies.
27
-
28
-
29
- ### Using the `DatabaseQueue` Class:
30
-
31
- ```py
32
- from queue_local.database_queue import DatabaseQueue
33
-
34
- q = DatabaseQueue() # you can also pass some parameters here, see the class definition for more info
35
-
36
- # Push items into the queue
37
- q.push({"item_description": "test 1", "action_id": 1, "parameters_json": "{'a': 1, 'b': 2}"})
38
- q.push({"item_description": "test 2", "action_id": 2, "parameters_json": {'a': 1, 'b': 2}})
39
-
40
- # Peek at the first item in the queue (without removing it)
41
- result1 = q.peek() # "test 1" is still in the queue
42
-
43
- # Get an item from the queue (and remove it) based on action_id
44
- result2 = q.get(action_ids=(2, )) # Gets "test 2" (the first item with action_id=2)
45
-
46
- # Get an item from the queue (and remove it)
47
- result3 = q.get() # Gets "test 1"
48
-
49
- q.close() # close the database connection
50
- ```
51
-
52
-
53
-
54
- ### Inheriting from the Abstract `OurQueue` Class:
55
-
56
- ```py
57
- from queue_local.our_queue import OurQueue
58
-
59
- class YourCustomQueue(OurQueue):
60
- def __init__(self):
61
- pass
62
-
63
- def push(self, item):
64
- """Push an item to the queue"""
65
- pass
66
-
67
- def get(self):
68
- """Get an item from the queue (and delete)"""
69
- pass
70
-
71
- def peek(self):
72
- """Peek at the head of the queue (without deleting)"""
73
- pass
74
- # Add any additional functions you need, such as is_empty()
75
- ```
File without changes