From: Michael Tremer Date: Thu, 13 Oct 2022 15:20:20 +0000 (+0000) Subject: jobs: Only send emails on fail X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=558b95bdac0cb5793bf48338ba6577fbe7d2bfbe;p=pbs.git jobs: Only send emails on fail Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index d43aed56..aa5f1517 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,6 +234,13 @@ dist_templates_events_modules_DATA = \ templates_events_modulesdir = $(templates_eventsdir)/modules +templates_jobsdir = $(templatesdir)/jobs + +dist_templates_jobs_messages_DATA = \ + src/templates/jobs/messages/failed.txt + +templates_jobs_messagesdir = $(templates_jobsdir)/messages + templates_messagesdir = $(templatesdir)/messages dist_templates_messages_builds_DATA = \ @@ -241,12 +248,6 @@ dist_templates_messages_builds_DATA = \ templates_messages_buildsdir = $(templates_messagesdir)/builds -dist_templates_messages_jobs_DATA = \ - src/templates/messages/jobs/failed.markdown \ - src/templates/messages/jobs/finished.markdown - -templates_messages_jobsdir = $(templates_messagesdir)/jobs - dist_templates_messages_users_DATA = \ src/templates/messages/users/email-activation.markdown diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index c0e53101..12912ef3 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -264,13 +264,14 @@ class Job(base.DataObject): # Store message self._set_attribute("message", message) - # Notify users - if success: - #self.send_finished_message() - pass # XXX send_finished_message() is currently broken - else: + # Handle any unsuccessful jobs + if not success: + # Mark as failed self._set_attribute("failed", True) - self.send_failed_message() + + # Notify the owner + if self.owner: + self.owner.send_message("jobs/messages/failed.txt", job=self) # XXX propagate any changes to the build @@ -473,24 +474,6 @@ class Job(base.DataObject): return pkgs - def send_finished_message(self): - # Send no finished mails for test jobs. - if self.test: - return - - logging.debug("Sending finished message for job %s to %s" % \ - (self.name, ", ".join(self.message_recipients))) - - self.backend.messages.send_template_to_many(self.message_recipients, - "messages/jobs/finished", job=self) - - def send_failed_message(self): - logging.debug("Sending failed message for job %s to %s" % \ - (self.name, ", ".join(self.message_recipients))) - - self.backend.messages.send_template_to_many(self.message_recipients, - "messages/jobs/failed", job=self) - @property def pakfire(self): """ diff --git a/src/templates/messages/jobs/failed.markdown b/src/templates/jobs/messages/failed.txt similarity index 77% rename from src/templates/messages/jobs/failed.markdown rename to src/templates/jobs/messages/failed.txt index 3094a5c7..5757e3d6 100644 --- a/src/templates/messages/jobs/failed.markdown +++ b/src/templates/jobs/messages/failed.txt @@ -1,4 +1,4 @@ -Subject: [{{ job.name }}] {{ _("Build job failed") }} +Subject: [{{ job.name }}] {{ _("Build Job Failed") }} {{ _("The build job %s has failed") % job.name }}. {{ _("This could have a couple of reasons and needs to be investigated by you.") }} @@ -11,5 +11,5 @@ Subject: [{{ job.name }}] {{ _("Build job failed") }} {{ _("Click on this link to get all details about the build:") }} {{ baseurl }}/job/{{ job.uuid }} -{{ _("Sincerely,") }} --{{ _("The Pakfire Build Service") }} \ No newline at end of file +{{ _("Sincerely,") }} +-{{ _("The Pakfire Build Service") }} diff --git a/src/templates/messages/jobs/finished.markdown b/src/templates/messages/jobs/finished.markdown deleted file mode 100644 index bb7cf373..00000000 --- a/src/templates/messages/jobs/finished.markdown +++ /dev/null @@ -1,11 +0,0 @@ -Subject: [{{ job.name }}] {{ _("Build job finished") }} - -{{ _("The build job %s has finished") % job.name }}. - -{{ _("If you are the maintainer, it is up to you to push it to one or more repositories.") }} - -{{ _("Click on this link to get all details about the build:") }} - {{ baseurl }}/job/{{ job.uuid }} - -{{ _("Sincerely,") }} --{{ _("The Pakfire Build Service") }} \ No newline at end of file