Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the Lock ID on the locks page #127

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Minion/Backend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ These fields are currently available:

Epoch time this lock will expire.

=item id

id => 1

Lock id.

=item name

name => 'foo'
Expand Down
8 changes: 7 additions & 1 deletion lib/Minion/Backend/Pg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sub list_locks {
my ($self, $offset, $limit, $options) = @_;

my $locks = $self->pg->db->query(
'SELECT name, EXTRACT(EPOCH FROM expires) AS expires, COUNT(*) OVER() AS total FROM minion_locks
'SELECT id, name, EXTRACT(EPOCH FROM expires) AS expires, COUNT(*) OVER() AS total FROM minion_locks
WHERE expires > NOW() AND (name = ANY ($1) OR $1 IS NULL)
ORDER BY id DESC LIMIT $2 OFFSET $3', $options->{names}, $limit, $offset
)->hashes->to_array;
Expand Down Expand Up @@ -727,6 +727,12 @@ These fields are currently available:

Epoch time this lock will expire.

=item id

id => 1

Lock id.

=item name

name => 'foo'
Expand Down
2 changes: 1 addition & 1 deletion lib/Minion/Command/minion/job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ sub _list_jobs {
sub _list_locks {
my $locks = shift->app->minion->backend->list_locks(@_)->{locks};
@$locks = map { Minion::_datetime($_) } @$locks;
print tablify [map { [@$_{qw(name expires)}] } @$locks];
print tablify [map { [@$_{qw(id name expires)}] } @$locks];
}

sub _list_workers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<thead>
<tr>
<th><input class="checkall" data-check="name" type="checkbox"></th>
<th>Lock ID</th>
<th>Name</th>
<th>Expires</th>
</tr>
Expand All @@ -37,6 +38,9 @@
<td>
<input type="checkbox" name="name" value="<%= $lock->{name} %>">
</td>
<td id="lock_id">
<%= $lock->{id} %>
</td>
<td>
<a href="<%= url_for->query({name => $lock->{name}}) %>">
<%= $lock->{name} %>
Expand Down
8 changes: 6 additions & 2 deletions t/pg_admin.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ subtest 'Workers' => sub {

subtest 'Locks' => sub {
$t->app->minion->lock('foo', 3600);
$t->get_ok('/minion/stats')->status_is(200)->json_is('/active_locks' => 1);
$t->app->minion->lock('bar', 3600);
$t->get_ok('/minion/stats')->status_is(200)->json_is('/active_locks' => 2);
$t->ua->max_redirects(5);
$t->get_ok('/minion/locks')->status_is(200)->text_like('tbody td a' => qr/bar/);
$t->get_ok('/minion/locks?name=foo')->status_is(200)->text_like('tbody td a' => qr/foo/);
$t->get_ok('/minion/locks')->status_is(200)->text_like('tbody td a' => qr/bar/);
$t->get_ok('/minion/locks')->status_is(200)->text_like('tbody td#lock_id' => qr/2/);
$t->get_ok('/minion/locks?name=foo')->status_is(200)->text_like('tbody td a' => qr/foo/);
$t->get_ok('/minion/locks?name=foo')->status_is(200)->text_like('tbody td#lock_id' => qr/1/);
$t->post_ok('/minion/locks?_method=DELETE&name=bar')->status_is(200)->text_like('tbody td a' => qr/foo/)
->text_like('.alert-success', qr/All selected named locks released/);
is $t->tx->previous->res->code, 302, 'right status';
Expand Down
Loading