]> git.ipfire.org Git - pbs.git/commitdiff
builds: Make sending emails async
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 May 2023 17:23:40 +0000 (17:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 May 2023 17:23:40 +0000 (17:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/web/builds.py

index 93da461e33de8a862c0eec6a3fb334a5c03fe5f0..038d45fd21d0b67521004538fe435baf9750007b 100644 (file)
@@ -528,12 +528,12 @@ class Build(base.DataObject):
 
        ## Comment stuff
 
-       def comment(self, *args, **kwargs):
+       async def comment(self, *args, **kwargs):
                """
                        Submits a comment
                """
                # Create a new comment
-               comment = self.backend.builds.comments.create(self, *args, **kwargs)
+               comment = await self.backend.builds.comments.create(self, *args, **kwargs)
 
                # Add to cache
                self.comments.append(comment)
@@ -700,10 +700,10 @@ class Build(base.DataObject):
 
                # Notify everyone this build has finished...
                if success:
-                       self._send_email("builds/messages/finished.txt")
+                       await self._send_email("builds/messages/finished.txt")
                # ... or that it has failed
                else:
-                       self._send_email("builds/messages/failed.txt")
+                       await self._send_email("builds/messages/failed.txt")
 
                # Create any test builds
                if success:
@@ -736,7 +736,7 @@ class Build(base.DataObject):
                """
                return self.has_finished() and not self.data.failed
 
-       def _send_email(self, *args, exclude=None, **kwargs):
+       async def _send_email(self, *args, exclude=None, **kwargs):
                """
                        Convenience function which sends an email to everybody who would care
                """
@@ -1062,7 +1062,7 @@ class Build(base.DataObject):
                        self.add_points(-2)
 
                        # Send an email on fail
-                       self._send_email("builds/messages/test-builds-failed.txt",
+                       await self._send_email("builds/messages/test-builds-failed.txt",
                                build=self, test_builds=self.test_builds)
 
 
@@ -1334,7 +1334,7 @@ class Comments(base.Object):
                        """, id,
                )
 
-       def create(self, build, user, text=None):
+       async def create(self, build, user, text=None):
                comment = self._get_comment("""
                        INSERT INTO
                                build_comments(
@@ -1349,7 +1349,7 @@ class Comments(base.Object):
                )
 
                # Notify people about this new comment
-               comment.notify()
+               await comment.notify()
 
                return comment
 
@@ -1369,9 +1369,9 @@ class Comment(base.DataObject):
        def text(self):
                return self.data.text
 
-       def notify(self):
+       async def notify(self):
                """
                        Notifies all watchers about this comment (except the user who posted it)
                """
-               self.build._send_email("builds/messages/comment.txt",
+               await self.build._send_email("builds/messages/comment.txt",
                        exclude=[self.user], build=self.build, comment=self)
index 120218047d737023ff727582b608044115754f6e..a8a60ba5aeea6643c68ee3f183199e98639e1914 100644 (file)
@@ -197,7 +197,7 @@ class UnwatchHandler(base.BaseHandler):
 
 class CommentHandler(base.BaseHandler):
        @tornado.web.authenticated
-       def post(self, uuid):
+       async def post(self, uuid):
                build = self.backend.builds.get_by_uuid(uuid)
                if not build:
                        raise tornado.web.HTTPError(404, "Could not find build %s" % uuid)
@@ -206,7 +206,7 @@ class CommentHandler(base.BaseHandler):
 
                # Add a new comment to the build
                with self.db.transaction():
-                       build.comment(self.current_user, text)
+                       await build.comment(self.current_user, text)
 
                # Redirect to the build
                self.redirect("/builds/%s" % build.uuid)