]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
cli: Add command to send all emails
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2017 17:02:15 +0000 (18:02 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2017 17:02:15 +0000 (18:02 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/messages.py
src/crontab/pakfire-build-service
src/scripts/pakfire-build-service

index 0c75377e3b8037ddd0701470181c65bcb24076a6..20e59b1844ea200a4db0738e61018e55810c7fd5 100644 (file)
@@ -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
index 90bd443a424c25b8a5679998ede600a19854693b..5db80568a97eeef9c0d47a3344925eb694b642b0 100644 (file)
@@ -1 +1,2 @@
-# Placeholder for any cron jobs
+# Send queued emails once a minute
+* * * * *      nobody  pakfire-build-service process-message-queue &>/dev/null
index fa7e4511181f71d01e040cfdab6a5bcebcf68c70..36d948d761748c5a937b6aea27fdc08c3ac848c8 100644 (file)
@@ -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: