From c06ce6d19dc1fb3ae79520f9925fa312e4764a46 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 6 Oct 2017 18:02:15 +0100 Subject: [PATCH] cli: Add command to send all emails Signed-off-by: Michael Tremer --- src/buildservice/messages.py | 13 +++++++++++++ src/crontab/pakfire-build-service | 3 ++- src/scripts/pakfire-build-service | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/buildservice/messages.py b/src/buildservice/messages.py index 0c75377..20e59b1 100644 --- a/src/buildservice/messages.py +++ b/src/buildservice/messages.py @@ -36,6 +36,16 @@ class Messages(base.Object): def delete(self, id): self.db.execute("DELETE FROM user_messages WHERE id = %s", id) + def process_queue(self): + # Get 10 messages at a time and send them one after the other + while True: + messages = self.get_all(limit=10) + + for message in messages: + self.send_msg(message) + else: + break + def send_to_all(self, recipients, subject, body, format=None): """ Sends an email to all recipients and does the translation. @@ -104,3 +114,6 @@ class Messages(base.Object): if p.returncode: raise Exception, "Could not send mail: %s" % stderr + + # If everything was okay, we can delete the message in the database. + self.delete(msg.id) \ No newline at end of file diff --git a/src/crontab/pakfire-build-service b/src/crontab/pakfire-build-service index 90bd443..5db8056 100644 --- a/src/crontab/pakfire-build-service +++ b/src/crontab/pakfire-build-service @@ -1 +1,2 @@ -# Placeholder for any cron jobs +# Send queued emails once a minute +* * * * * nobody pakfire-build-service process-message-queue &>/dev/null diff --git a/src/scripts/pakfire-build-service b/src/scripts/pakfire-build-service index fa7e451..36d948d 100644 --- a/src/scripts/pakfire-build-service +++ b/src/scripts/pakfire-build-service @@ -13,7 +13,10 @@ class Cli(object): # Initialise backend self.backend = pakfire.buildservice.Backend(*args, **kwargs) - self._commands = {} + self._commands = { + # Sends all queued messages + "process-message-queue" : self.backend.messages.process_queue, + } def __call__(self, *args): if not len(args) >= 2: -- 2.39.2