queue-local 0.0.44__tar.gz → 0.0.46__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.44
3
+ Version: 0.0.46
4
4
  Home-page: https://github.com/circles-zone/queue-local-python-package
5
5
  Author: Circles
6
6
  Author-email: info@circles.life
@@ -29,7 +29,7 @@ class QueueStatusEnum(Enum):
29
29
  class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_logger_object):
30
30
  """A queue that uses a database table as the queue."""
31
31
 
32
- def __init__(self, schema_name: str = "queue", table_name: str = "queue_item_table",
32
+ def __init__(self, *, schema_name: str = "queue", table_name: str = "queue_item_table",
33
33
  view_name: str = "queue_item_view", id_column_name: str = "queue_item_id",
34
34
  is_test_data: bool = False) -> None:
35
35
  """Initialize the queue.
@@ -77,22 +77,28 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
77
77
 
78
78
  self._fix_parameters_json(data_json)
79
79
 
80
- # TODO StatusEnum -> QueueStatusEnum
81
80
  data_json["queue_status_id"] = QueueStatusEnum.NEW.value
82
81
  data_json["created_user_id"] = created_user_id
83
82
 
84
- return self.insert(data_json=data_json)
83
+ if self.id_column_name in data_json:
84
+ id_column_value = data_json[self.id_column_name]
85
+ del data_json[self.id_column_name]
86
+ self.update_by_id(id_column_value=id_column_value, data_json=data_json)
87
+ return id_column_value
88
+ else:
89
+ return self.insert(data_json=data_json)
85
90
 
86
91
  def push_back(self, queue_item: dict) -> None:
87
92
  """Push a taken queue item back to the queue."""
88
93
  data_json = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
89
94
  self.update_by_id(id_column_value=queue_item[self.id_column_name], data_json=data_json)
90
95
 
91
- def get(self, action_ids: tuple = ()) -> dict:
96
+ def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
92
97
  """
93
98
  Returns the first item from the queue (possibly considering specific actions) and marks it as taken.
94
99
 
95
100
  :param action_ids: Tuple of action IDs to consider (optional).
101
+ :param custom_condition: Custom condition to add to the WHERE clause (optional).
96
102
  :return: Dictionary representing the retrieved queue item.
97
103
  """
98
104
  updated_user_id = self.user_context.get_effective_user_id()
@@ -100,8 +106,9 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
100
106
 
101
107
  data_json = {"process_id": os.getpid()}
102
108
  update_where = f"process_id IS NULL AND queue_status_id = {QueueStatusEnum.NEW.value} AND " \
103
- f"NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp)" + \
104
- (f" AND action_id IN {action_ids}" if action_ids else "")
109
+ f"NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
110
+ (f"AND action_id IN {action_ids} " if action_ids else "") + \
111
+ (f"AND {custom_condition}" if custom_condition else "")
105
112
  self.update_by_where(where=update_where, order_by=self.id_column_name, limit=1, data_json=data_json)
106
113
 
107
114
  select_where = f"process_id = {os.getpid()} AND queue_status_id = {QueueStatusEnum.NEW.value}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: queue-local
3
- Version: 0.0.44
3
+ Version: 0.0.46
4
4
  Home-page: https://github.com/circles-zone/queue-local-python-package
5
5
  Author: Circles
6
6
  Author-email: info@circles.life
@@ -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.44',
8
+ version='0.0.46',
9
9
  author="Circles",
10
10
  author_email="info@circles.life",
11
11
  url=f"https://github.com/circles-zone/{PACKAGE_NAME}-python-package",
File without changes
File without changes