Skip to content

Commit

Permalink
Improve Mojolicious::Plugin::Minion::Admin to log whenever a job gets…
Browse files Browse the repository at this point in the history
… removed
  • Loading branch information
kraih committed Apr 28, 2022
1 parent cc18dcc commit 69c38bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

10.24 2022-01-21
10.24 2022-04-28
- Improved Mojolicious::Plugin::Minion::Admin to log whenever a job gets removed.

10.23 2022-01-20
- Improved repair performance in Minion::Backend::Pg. (andrii-suse, ilmari, kraih)
Expand Down
9 changes: 7 additions & 2 deletions lib/Mojolicious/Plugin/Minion/Admin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ sub _manage_jobs {
}
elsif ($do eq 'remove') {
my $fail = grep { $minion->job($_)->remove ? () : 1 } @$ids;
if ($fail) { $c->flash(danger => "Couldn't remove all jobs.") }
else { $c->flash(success => 'All selected jobs removed.') }
if ($fail) { $c->flash(danger => "Couldn't remove all jobs.") }
else {
$c->flash(success => 'All selected jobs removed.');
my $id_list = join ', ', @$ids;
my $remote_address = $c->tx->remote_address;
$c->log->debug(qq{Jobs removed by user "$remote_address": $id_list});
}
}
elsif ($do eq 'stop') {
$minion->broadcast(stop => [$_]) for @$ids;
Expand Down
9 changes: 9 additions & 0 deletions t/pg_admin.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,17 @@ subtest 'Manage jobs' => sub {
->text_like('.alert-info', qr/Trying to stop all selected jobs/);
is $t->tx->previous->res->code, 302, 'right status';
like $t->tx->previous->res->headers->location, qr/id=$finished/, 'right "Location" value';

my $subscribers = $t->app->log->subscribers('message');
my $level = $t->app->log->level;
$t->app->log->unsubscribe('message');
my $log = '';
my $cb = $t->app->log->level('debug')->on(message => sub { $log .= pop });
$t->post_ok('/minion/jobs?_method=PATCH' => form => {id => $finished, do => 'remove'})
->text_like('.alert-success', qr/All selected jobs removed/);
$t->app->log->level($level)->unsubscribe(message => $cb);
$t->app->log->on(message => $_) for @$subscribers;
like $log, qr/Jobs removed by user ".+": $finished/, 'right log message';
is $t->tx->previous->res->code, 302, 'right status';
like $t->tx->previous->res->headers->location, qr/id=$finished/, 'right "Location" value';
is app->minion->job($finished), undef, 'job has been removed';
Expand Down

0 comments on commit 69c38bc

Please sign in to comment.