Skip to content

Commit

Permalink
Add delay for queue processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-piles committed Oct 4, 2024
1 parent 26c9413 commit 8cc6ff4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name=PROJECT_NAME,
packages=["queue_processor"],
package_dir={"": "src"},
version="0.4",
version="0.5",
url="https://github.com/huridocs/queue-processor",
author="HURIDOCS",
description="Manage queues on Uwazi services",
Expand Down
16 changes: 13 additions & 3 deletions src/queue_processor/QueueProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@


class QueueProcessor:
def __init__(self, redis_host: str, redis_port: int, queues_names_by_priority: list[str], logger: logging.Logger = None):
def __init__(
self,
redis_host: str,
redis_port: int,
queues_names_by_priority: list[str],
logger: logging.Logger = None,
delay_time_for_results: int = 0,
):

self.redis_host: str = redis_host
self.redis_port: int = redis_port
self.task_queues_names: list[str] = [queue_name + "_tasks" for queue_name in queues_names_by_priority]
self.results_queues_names: list[str] = [queue_name + "_results" for queue_name in queues_names_by_priority]

self.delay_time_for_results = delay_time_for_results
self.exists_queues = False
if logger:
self.queue_processor_logger = logger
Expand Down Expand Up @@ -49,7 +57,9 @@ def start(self, process: callable):
results = process(utils.decode_message(message["message"]))

if results:
self.get_queue(results_queue_name).sendMessage().message(results).execute()
self.get_queue(results_queue_name).sendMessage(delay=self.delay_time_for_results).message(
results
).execute()
break

except NoMessageInQueue:
Expand Down

0 comments on commit 8cc6ff4

Please sign in to comment.