From aaaeaa3dba389ec9181b990d9317b9aed627b044 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Fri, 31 Jan 2025 10:57:28 +0100 Subject: [PATCH 1/2] add backend-agnostic connection check This is useful for avoiding database connection getting idle. --- lib/Minion/Backend.pm | 8 ++++++++ lib/Minion/Backend/Pg.pm | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/Minion/Backend.pm b/lib/Minion/Backend.pm index 6b783ce..0c1c3d0 100644 --- a/lib/Minion/Backend.pm +++ b/lib/Minion/Backend.pm @@ -23,6 +23,7 @@ sub list_locks { croak 'Method "list_locks" not implemented by subclass' sub list_workers { croak 'Method "list_workers" not implemented by subclass' } sub lock { croak 'Method "lock" not implemented by subclass' } sub note { croak 'Method "note" not implemented by subclass' } +sub ping { croak 'Method "ping" not implemented by subclass' } sub receive { croak 'Method "receive" not implemented by subclass' } sub register_worker { croak 'Method "register_worker" not implemented by subclass' } sub remove_job { croak 'Method "remove_job" not implemented by subclass' } @@ -57,6 +58,7 @@ Minion::Backend - Backend base class sub list_workers {...} sub lock {...} sub note {...} + sub ping {...} sub receive {...} sub register_worker {...} sub remove_job {...} @@ -616,6 +618,12 @@ Number of shared locks with the same name that can be active at the same time, d Change one or more metadata fields for a job. Setting a value to C<undef> will remove the field. Meant to be overloaded in a subclass. +=head2 ping + + my $bool = $backend->ping; + +Check backend connection. + =head2 receive my $commands = $backend->receive($worker_id); diff --git a/lib/Minion/Backend/Pg.pm b/lib/Minion/Backend/Pg.pm index 7acca2e..0472323 100644 --- a/lib/Minion/Backend/Pg.pm +++ b/lib/Minion/Backend/Pg.pm @@ -16,6 +16,11 @@ sub broadcast { {json => [[$command, @$args]]}, $ids)->rows; } +sub ping { + my ($self) = @_; + return $self->pg->db->ping(); +} + sub dequeue { my ($self, $id, $wait, $options) = @_; From 5f053267aab1693d6e059a705332ef269d6e49d6 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Tue, 18 Feb 2025 16:49:14 +0100 Subject: [PATCH 2/2] better method documentation --- lib/Minion/Backend.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Minion/Backend.pm b/lib/Minion/Backend.pm index 0c1c3d0..5d2cea7 100644 --- a/lib/Minion/Backend.pm +++ b/lib/Minion/Backend.pm @@ -622,7 +622,7 @@ in a subclass. my $bool = $backend->ping; -Check backend connection. +Shortcut to underlying database object C<ping> method, useful for avoiding connexion timeout. =head2 receive