From: Michael Tremer Date: Fri, 19 May 2023 17:23:40 +0000 (+0000) Subject: builds: Make sending emails async X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c99ba04466f08f2be6beea9023a95a463a10aa24;p=pbs.git builds: Make sending emails async Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 93da461e..038d45fd 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -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) diff --git a/src/web/builds.py b/src/web/builds.py index 12021804..a8a60ba5 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -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)