From 90cbf563453b5d437fbdf06d019e6cd0b2f02eaf Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Wed, 13 Mar 2024 19:06:38 +0000 Subject: [PATCH] Expose the Lock ID on the locks page --- lib/Minion/Backend.pm | 6 ++++++ lib/Minion/Backend/Pg.pm | 8 +++++++- lib/Minion/Command/minion/job.pm | 2 +- .../Minion/resources/templates/minion/locks.html.ep | 4 ++++ t/pg_admin.t | 8 ++++++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/Minion/Backend.pm b/lib/Minion/Backend.pm index e9d1a0cc..6b783ce6 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 8f2e40f0..9ac18c33 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 9e21e028..71a7c2c0 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 3cefe7eb..8210f602 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 a9b2fa77..a789aeea 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?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';