queue-local 0.0.45__tar.gz → 0.0.47__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.45
3
+ Version: 0.0.47
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,34 +77,47 @@ 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
+ # TODO push_result = id_column_value
88
+ return id_column_value
89
+ else:
90
+ # TODO push_result = elf.insert(data_json=data_json)
91
+ return self.insert(data_json=data_json)
92
+ # TODO Can we do this everywhere?
93
+ # TODO logger.end("...", {'push_result': push_result} )
94
+ # TODO return push_result
85
95
 
86
96
  def push_back(self, queue_item: dict) -> None:
87
97
  """Push a taken queue item back to the queue."""
88
98
  data_json = {"queue_status_id": QueueStatusEnum.NEW.value, "process_id": None}
89
99
  self.update_by_id(id_column_value=queue_item[self.id_column_name], data_json=data_json)
90
100
 
91
- def get(self, action_ids: tuple = ()) -> dict:
101
+ def get(self, *, action_ids: tuple = (), custom_condition: str = "") -> dict:
92
102
  """
93
103
  Returns the first item from the queue (possibly considering specific actions) and marks it as taken.
94
104
 
95
105
  :param action_ids: Tuple of action IDs to consider (optional).
106
+ :param custom_condition: Custom condition to add to the WHERE clause (optional).
96
107
  :return: Dictionary representing the retrieved queue item.
97
108
  """
98
109
  updated_user_id = self.user_context.get_effective_user_id()
99
110
  action_ids = self._fix_action_ids(action_ids)
100
111
 
101
112
  data_json = {"process_id": os.getpid()}
102
- 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 "")
113
+ update_where = f"process_id IS NULL " \
114
+ f"AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value}) " \
115
+ f"AND NOW() > start_timestamp AND (end_timestamp is NULL or NOW() < end_timestamp) " + \
116
+ (f"AND action_id IN {action_ids} " if action_ids else "") + \
117
+ (f"AND {custom_condition}" if custom_condition else "")
105
118
  self.update_by_where(where=update_where, order_by=self.id_column_name, limit=1, data_json=data_json)
106
119
 
107
- select_where = f"process_id = {os.getpid()} AND queue_status_id = {QueueStatusEnum.NEW.value}"
120
+ select_where = f"process_id = {os.getpid()} AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})"
108
121
  queue_item = self.select_one_dict_by_where(where=select_where)
109
122
  if queue_item:
110
123
  # Update the selected queue item
@@ -124,7 +137,7 @@ class DatabaseQueue(OurQueue, GenericCRUD, metaclass=MetaLogger, object=queue_lo
124
137
  def peek(self, action_ids: tuple = ()) -> dict:
125
138
  """Get the first item in the queue without changing it"""
126
139
  action_ids = self._fix_action_ids(action_ids)
127
- where = f"process_id IS NULL AND queue_status_id = {QueueStatusEnum.NEW.value}" + \
140
+ where = f"process_id IS NULL AND (queue_status_id IS NULL OR queue_status_id = {QueueStatusEnum.NEW.value})" + \
128
141
  (f" AND action_id IN {action_ids}" if action_ids else "")
129
142
  # SELECT * FROM `queue`.`queue_item_view` WHERE process_id IS NULL AND queue_status_id = 0
130
143
  # AND action_id IN (1, 2, 3) ORDER BY queue_item_id LIMIT 1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: queue-local
3
- Version: 0.0.45
3
+ Version: 0.0.47
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.45',
8
+ version='0.0.47',
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