summaryrefslogtreecommitdiffstats
path: root/extensions/BMO/lib/Reports/EmailQueue.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/BMO/lib/Reports/EmailQueue.pm')
-rw-r--r--extensions/BMO/lib/Reports/EmailQueue.pm69
1 files changed, 69 insertions, 0 deletions
diff --git a/extensions/BMO/lib/Reports/EmailQueue.pm b/extensions/BMO/lib/Reports/EmailQueue.pm
new file mode 100644
index 000000000..1bf2ca003
--- /dev/null
+++ b/extensions/BMO/lib/Reports/EmailQueue.pm
@@ -0,0 +1,69 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::BMO::Reports::EmailQueue;
+use strict;
+use warnings;
+
+use Bugzilla::Error;
+use Scalar::Util qw(blessed);
+use Storable ();
+
+sub report {
+ my ($vars, $filter) = @_;
+ my $dbh = Bugzilla->dbh;
+ my $user = Bugzilla->user;
+
+ $user->in_group('admin') || $user->in_group('infra')
+ || ThrowUserError('auth_failure', { group => 'admin',
+ action => 'run',
+ object => 'email_queue' });
+
+ my $query = "
+ SELECT j.jobid,
+ j.arg,
+ j.insert_time,
+ j.run_after AS run_time,
+ COUNT(e.jobid) AS error_count,
+ MAX(e.error_time) AS error_time,
+ e.message AS error_message
+ FROM ts_job j
+ LEFT JOIN ts_error e ON e.jobid = j.jobid
+ GROUP BY j.jobid
+ ORDER BY j.run_after";
+
+ $vars->{'jobs'} = $dbh->selectall_arrayref($query, { Slice => {} });
+ foreach my $job (@{ $vars->{'jobs'} }) {
+ eval {
+ my $msg = _cond_thaw(delete $job->{'arg'})->{msg};
+ if (ref($msg) && blessed($msg) eq 'Email::MIME') {
+ $job->{'subject'} = $msg->header('subject');
+ } else {
+ ($job->{'subject'}) = $msg =~ /\nSubject: ([^\n]+)/;
+ }
+ };
+ }
+ $vars->{'now'} = (time);
+}
+
+sub _cond_thaw {
+ my $data = shift;
+ my $magic = eval { Storable::read_magic($data); };
+ if ($magic && $magic->{major} && $magic->{major} >= 2 && $magic->{major} <= 5) {
+ my $thawed = eval { Storable::thaw($data) };
+ if ($@) {
+ # false alarm... looked like a Storable, but wasn't.
+ return $data;
+ }
+ return $thawed;
+ } else {
+ return $data;
+ }
+}
+
+
+1;