From 908480c98aa48a9d1caf09ee00f3cfe0863afec2 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Fri, 31 Oct 2014 15:20:42 +0800 Subject: Bug 1062739: add the ability for administrators to limit the number of emails sent to a user per minute and hour r=dylan,a=glob --- Bugzilla/Job/BugMail.pm | 16 +++------------- Bugzilla/Job/Mailer.pm | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'Bugzilla/Job') diff --git a/Bugzilla/Job/BugMail.pm b/Bugzilla/Job/BugMail.pm index e0b7f5448..b4887c470 100644 --- a/Bugzilla/Job/BugMail.pm +++ b/Bugzilla/Job/BugMail.pm @@ -14,19 +14,9 @@ use warnings; use Bugzilla::BugMail; BEGIN { eval "use parent qw(Bugzilla::Job::Mailer)"; } -sub work { - my ($class, $job) = @_; - my $success = eval { - Bugzilla::BugMail::dequeue($job->arg->{vars}); - 1; - }; - if (!$success) { - $job->failed($@); - undef $@; - } - else { - $job->completed; - } +sub process_job { + my ($class, $arg) = @_; + Bugzilla::BugMail::dequeue($arg->{vars}); } 1; diff --git a/Bugzilla/Job/Mailer.pm b/Bugzilla/Job/Mailer.pm index cd1c23445..7e7549de8 100644 --- a/Bugzilla/Job/Mailer.pm +++ b/Bugzilla/Job/Mailer.pm @@ -11,6 +11,7 @@ use 5.10.1; use strict; use warnings; +use Bugzilla::Constants; use Bugzilla::Mailer; BEGIN { eval "use parent qw(TheSchwartz::Worker)"; } @@ -32,15 +33,24 @@ sub retry_delay { sub work { my ($class, $job) = @_; - my $msg = $job->arg->{msg}; - my $success = eval { MessageToMTA($msg, 1); 1; }; - if (!$success) { - $job->failed($@); + eval { $class->process_job($job->arg) }; + if (my $error = $@) { + if ($error eq EMAIL_LIMIT_EXCEPTION) { + $job->declined(); + } + else { + $job->failed($error); + } undef $@; - } + } else { $job->completed; } } +sub process_job { + my ($class, $arg) = @_; + MessageToMTA($arg, 1); +} + 1; -- cgit v1.2.3-24-g4f1b