diff options
author | Jeff Fearn <jfearn@redhat.com> | 2022-08-05 12:33:38 +1000 |
---|---|---|
committer | Jeff Fearn <jfearn@redhat.com> | 2022-08-05 12:52:15 +1000 |
commit | 15a79582f65749a71420ba76405d6dccbdfbcb72 (patch) | |
tree | 39b72c94ec34c27260ad41932b0094943647ef04 | |
parent | Bug 2086767 - Explain the changed check boxes on the bulk edit form (diff) | |
download | bugzilla-15a79582f65749a71420ba76405d6dccbdfbcb72.tar.gz bugzilla-15a79582f65749a71420ba76405d6dccbdfbcb72.tar.bz2 bugzilla-15a79582f65749a71420ba76405d6dccbdfbcb72.zip |
Bug 2094129 - Allow admins to reset timers on stuck jobs
Added API call to reschedule jobs.
Added icon to job queue report to trigger API call.
Cleaned up time display on report.
Change-Id: I0036a290d22dc7de9594f4511e6e8968bb488bbd
-rw-r--r-- | Bugzilla/Util.pm | 23 | ||||
-rw-r--r-- | extensions/ActivityReport/lib/Reports.pm | 2 | ||||
-rw-r--r-- | extensions/ActivityReport/template/en/default/pages/email_queue.html.tmpl | 16 | ||||
-rw-r--r-- | extensions/RedHat/Extension.pm | 14 | ||||
-rw-r--r-- | extensions/RedHat/lib/WebService/Bugzilla.pm | 85 | ||||
-rw-r--r-- | extensions/RedHat/web/js/redhat.js | 19 | ||||
-rw-r--r-- | extensions/RuleEngine/lib/Job.pm | 2 |
7 files changed, 150 insertions, 11 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 56f5338f1..9c8e17666 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -24,7 +24,9 @@ use parent qw(Exporter); validate_email_syntax check_email_syntax clean_text get_text template_var display_value disable_utf8 detect_encoding email_filter - join_activity_entries read_text write_text redact); + join_activity_entries read_text write_text redact + format_unixtime +); use Bugzilla::Constants; use Bugzilla::RNG qw(irand); @@ -985,6 +987,18 @@ sub redact { } ## RED HAT EXTENSION END 1759744 +## RED HAT EXTENSION START 2094129 +sub format_unixtime { + my $time = shift; + my $format = shift; + + my $tz = Bugzilla->user->timezone; + my $dt = DateTime->now(); + my $tzsn = $tz->short_name_for_datetime($dt); + return time2str($format, $time, $tzsn); +} +## RED HAT EXTENSION END 2094129 + 1; __END__ @@ -1305,6 +1319,13 @@ You can optionally specify a timezone for the returned date. If not specified, defaults to the currently-logged-in user's timezone, or the Bugzilla server's local timezone if there isn't a logged-in user. +=item C<format_unixtime($time, $format)> + +Takes a unixtime and formats it to the supplied format using the user's timeone. + +This routine can be called from templates to filter times, see +"FILTER unixtime" in L<Bugzilla::Extension::RedHat>. + =back =head2 Cryptography diff --git a/extensions/ActivityReport/lib/Reports.pm b/extensions/ActivityReport/lib/Reports.pm index e1e0bbf6f..d94e4fb97 100644 --- a/extensions/ActivityReport/lib/Reports.pm +++ b/extensions/ActivityReport/lib/Reports.pm @@ -549,7 +549,7 @@ sub email_queue_report { SELECT j.jobid, j.insert_time, - j.run_after AS run_time, + j.run_after, COUNT(e.jobid) AS error_count, MAX(e.error_time) AS error_time, ( diff --git a/extensions/ActivityReport/template/en/default/pages/email_queue.html.tmpl b/extensions/ActivityReport/template/en/default/pages/email_queue.html.tmpl index 537b744cf..3243a70b6 100644 --- a/extensions/ActivityReport/template/en/default/pages/email_queue.html.tmpl +++ b/extensions/ActivityReport/template/en/default/pages/email_queue.html.tmpl @@ -36,8 +36,9 @@ <table id="job_report"> <thead> <tr> + <th>ID</th> <th>Insert Time</th> - <th>Run Time</th> + <th>Run After</th> <th>Age</th> <th>Error Count</th> <th>Last Error</th> @@ -49,8 +50,9 @@ <tbody> [% FOREACH job IN jobs %] <tr id="job_row_[% job.jobid FILTER html %]"> - <td>[% time2str("%Y-%m-%d %H:%M:%S %Z", job.insert_time) FILTER html %]</td> - <td>[% time2str("%Y-%m-%d %H:%M:%S %Z", job.run_time) FILTER html %]</td> + <td>[% job.jobid FILTER html %]</td> + <td>[% job.insert_time FILTER unixtime("%Y-%m-%d %H:%M %Z") %]</td> + <td class="run_after">[% job.run_after FILTER unixtime("%Y-%m-%d %H:%M %Z") %]</td> <td> [% age = now - job.insert_time %] [% IF age < 60 %] @@ -82,6 +84,8 @@ <a title="Delete" onclick="delete_job(this, [% job.jobid FILTER html %])"><i class="fas fa-trash"></i></a> <a title="View" onclick="view_job(this, [% job.jobid FILTER html %])"><i class="fas fa-eye"></i></a> + + <a title="Reschedule" onclick="reschedule_job(this, [% job.jobid FILTER html %])"><i class="fas fa-history"></i></a> [% END %] </td> </tr> @@ -96,8 +100,12 @@ $(document).ready(function() { pagingType: 'full_numbers', aLengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All']], [% IF user.settings.def_table_size.value %] - iDisplayLength: [% user.settings.def_table_size.value FILTER html %] + iDisplayLength: [% user.settings.def_table_size.value FILTER html %], [%- END %] + columnDefs: [ + { "searchable": false, "targets": [-1] }, + { "orderable": false, "targets": [-1] } + ], }); }); </script> diff --git a/extensions/RedHat/Extension.pm b/extensions/RedHat/Extension.pm index 8ddda397f..e3910b141 100644 --- a/extensions/RedHat/Extension.pm +++ b/extensions/RedHat/Extension.pm @@ -42,6 +42,7 @@ use Scalar::Util qw(blessed); use Bugzilla::User::APIKey; use URI::Escape; use HTML::Scrubber; +use Date::Format; our $VERSION = 0.3; @@ -4575,6 +4576,19 @@ sub template_before_create { 1 ]; + ## RED HAT EXTENSION START 2094129 + $args->{config}->{FILTERS}->{unixtime} = [ + sub { + my ($context, $format) = @_; + return sub { + my $time = shift; + return format_unixtime($time, $format); + }; + }, + 1 + ]; + ## RED HAT EXTENSION END 2094129 + return; } diff --git a/extensions/RedHat/lib/WebService/Bugzilla.pm b/extensions/RedHat/lib/WebService/Bugzilla.pm index fae3bb3a7..28c7df362 100644 --- a/extensions/RedHat/lib/WebService/Bugzilla.pm +++ b/extensions/RedHat/lib/WebService/Bugzilla.pm @@ -26,6 +26,7 @@ use List::MoreUtils qw(any none); use Bugzilla::Token qw(issue_hash_token); use Bugzilla::Report; use List::Compare; +use Date::Format; use constant PUBLIC_METHODS => qw( product_get_objects @@ -48,6 +49,7 @@ use constant PUBLIC_METHODS => qw( delete_jobs view_jobs tag_user_comments_as_spam + reschedule_jobs ); =pod @@ -2325,8 +2327,7 @@ sub delete_jobs { my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction; my $count = $dbh->do( - 'DELETE FROM ts_job WHERE jobid IN (' - . join(',', (('?') x scalar(@ids))) . ')', + 'DELETE FROM ts_job WHERE jobid IN (' . join(',', (('?') x scalar(@ids))) . ')', undef, @ids ); $dbh->bz_commit_transaction; @@ -2426,8 +2427,6 @@ sub view_jobs { push(@results, _job_to_hash($jobs[0])) if ($jobs[0]); } - Bugzilla->logger->info(Dumper(\@results)); - return {jobs => \@results}; } @@ -2439,6 +2438,84 @@ sub _job_to_hash { return (\%job); } +## REDHAT EXTENSION START 2094129 + +=head2 reschedule_jobs + +Reset the run_after time for jobs. + +You must be in the I<admin> group to use this API. + +=head3 Params + +ids: + B<array-of-integers> The ids of the Jobs to reset. + +=head3 Returns + +A hash containing the new run_after time and the count of jobs reset. + +=head3 Examples + +=head4 JSONRPC call + + { + "jsonrpc": "2.0", + "method": "RedHat.reschedule_jobs", + "id": 11, + "params": [ + { + "ids": [11, 12, 42] + } + ] + } + +=head4 JSONRPC reply + + { + "error": null, + "result": { + "run_after": "???", + "updated_count": 1 + }, + "id": 11 + } + +=cut + +sub reschedule_jobs { + my $self = shift; + my ($params) = @_; + + my $user = Bugzilla->login(LOGIN_REQUIRED); + + $user->in_group('admin') + || ThrowUserError("auth_failure", + {group => "admin", action => "run", object => "reschedule_jobs"}); + + my $ids + = $params->{ids} + || ThrowCodeError('params_required', + {function => 'RedHat.reschedule_jobs', params => ['ids']}); + + my @ids = map { _clean_id($_) } @$ids; + my $new_time = time() + 60; + + my $dbh = Bugzilla->dbh; + $dbh->bz_start_transaction; + my $count = $dbh->do( + 'UPDATE ts_job SET run_after = ? WHERE jobid IN (' + . join(',', (('?') x scalar(@ids))) . ')', + undef, $new_time, @ids + ); + $dbh->bz_commit_transaction; + + my $f_time = format_unixtime($new_time, '%Y-%m-%d %H:%M %Z'); + + return {updated_count => $count, run_after => $f_time}; +} +## REDHAT EXTENSION END 2094129 + ## REDHAT EXTENSION START 2056724 =head2 tag_user_comments_as_spam diff --git a/extensions/RedHat/web/js/redhat.js b/extensions/RedHat/web/js/redhat.js index 9cbb01c3d..9b7554e04 100644 --- a/extensions/RedHat/web/js/redhat.js +++ b/extensions/RedHat/web/js/redhat.js @@ -1215,6 +1215,25 @@ function view_job(ev, jobid) { }); } +function reschedule_job(ev, jobid) { + var data = {}; + data['ids'] = [jobid]; + + $(ev)._onAjaxSend(); + + return rpc = new Rpc('RedHat', 'reschedule_jobs', data) + .complete(function (cb) { + $(ev)._onAjaxComplete(); + }) + .fail(function (error) { + warn(error); + }) + .done(function (res) { + alertify.success("Job " + jobid + " rescheduled."); + $('#job_row_' + jobid + ' .run_after').text(res.run_after); + }); +} + function blockSubmit() { $(window).keydown(function(event){ if(event.keyCode == 13) { diff --git a/extensions/RuleEngine/lib/Job.pm b/extensions/RuleEngine/lib/Job.pm index 85c6642fa..29a022831 100644 --- a/extensions/RuleEngine/lib/Job.pm +++ b/extensions/RuleEngine/lib/Job.pm @@ -42,7 +42,7 @@ use constant grab_for => 300; # 6 hours. use constant max_retries => 36; -# If it fails, retry after 10 mintes +# If it fails, retry after 10 minutes use constant retry_delay => 600; use constant BUG_FIELD_MAP => { |