diff --git a/lib/Minion/Backend.pm b/lib/Minion/Backend.pm index e9d1a0c..6b783ce 100644 --- a/lib/Minion/Backend.pm +++ b/lib/Minion/Backend.pm @@ -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' diff --git a/lib/Minion/Backend/Pg.pm b/lib/Minion/Backend/Pg.pm index 8f2e40f..9ac18c3 100644 --- a/lib/Minion/Backend/Pg.pm +++ b/lib/Minion/Backend/Pg.pm @@ -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; @@ -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' diff --git a/lib/Minion/Command/minion/job.pm b/lib/Minion/Command/minion/job.pm index 9e21e02..71a7c2c 100644 --- a/lib/Minion/Command/minion/job.pm +++ b/lib/Minion/Command/minion/job.pm @@ -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 { diff --git a/lib/Mojolicious/Plugin/Minion/resources/templates/minion/locks.html.ep b/lib/Mojolicious/Plugin/Minion/resources/templates/minion/locks.html.ep index 3cefe7e..8210f60 100644 --- a/lib/Mojolicious/Plugin/Minion/resources/templates/minion/locks.html.ep +++ b/lib/Mojolicious/Plugin/Minion/resources/templates/minion/locks.html.ep @@ -23,6 +23,7 @@ + Lock ID Name Expires @@ -37,6 +38,9 @@ + + <%= $lock->{id} %> + <%= $lock->{name} %> diff --git a/t/pg_admin.t b/t/pg_admin.t index a9b2fa7..752bf2c 100644 --- a/t/pg_admin.t +++ b/t/pg_admin.t @@ -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')->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';