Skip to content

Instantly share code, notes, and snippets.

/latency.diff Secret

Created April 17, 2016 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/993d9ffb6ca32259d306caf705e89ad3 to your computer and use it in GitHub Desktop.
Save anonymous/993d9ffb6ca32259d306caf705e89ad3 to your computer and use it in GitHub Desktop.
diff --git a/lib/Minion.pm b/lib/Minion.pm
index 29b3860..72afa74 100644
--- a/lib/Minion.pm
+++ b/lib/Minion.pm
@@ -451,6 +451,13 @@ Number of jobs in C<inactive> state.
Number of workers that are currently not processing a job.
+=item latency
+
+ latency => 0.25
+
+Estimated time in seconds for a job enqueued into the C<default> queue to be
+dequeued by a worker.
+
=back
=head2 worker
diff --git a/lib/Minion/Backend.pm b/lib/Minion/Backend.pm
index 38e2b13..4aa526f 100644
--- a/lib/Minion/Backend.pm
+++ b/lib/Minion/Backend.pm
@@ -432,6 +432,13 @@ Number of jobs in C<inactive> state.
Number of workers that are currently not processing a job.
+=item latency
+
+ latency => 0.25
+
+Estimated time in seconds for a job enqueued into the C<default> queue to be
+dequeued by a worker.
+
=back
=head2 unregister_worker
diff --git a/lib/Minion/Backend/Pg.pm b/lib/Minion/Backend/Pg.pm
index 5d2c505..868144a 100644
--- a/lib/Minion/Backend/Pg.pm
+++ b/lib/Minion/Backend/Pg.pm
@@ -150,6 +150,12 @@ sub stats {
my $stats = $self->pg->db->query(
"select state::text || '_jobs', count(state) from minion_jobs group by state
union all
+ select 'latency', coalesce(extract(epoch from (now () - f.delayed)), 0)
+ from (
+ select min(delayed) as delayed from minion_jobs where state = 'inactive'
+ and queue = 'default' and delayed <= now()
+ ) as f
+ union all
select 'inactive_workers', count(*) from minion_workers
union all
select 'active_workers', count(distinct worker) from minion_jobs
@@ -600,6 +606,13 @@ Number of jobs in C<inactive> state.
Number of workers that are currently not processing a job.
+=item latency
+
+ latency => 0.25
+
+Estimated time in seconds for a job enqueued into the C<default> queue to be
+dequeued by a worker.
+
=back
=head2 unregister_worker
diff --git a/lib/Minion/Command/minion/job.pm b/lib/Minion/Command/minion/job.pm
index 92e86a5..ae6ea19 100644
--- a/lib/Minion/Command/minion/job.pm
+++ b/lib/Minion/Command/minion/job.pm
@@ -88,6 +88,7 @@ sub _stats {
say "Active jobs: $stats->{active_jobs}";
say "Failed jobs: $stats->{failed_jobs}";
say "Finished jobs: $stats->{finished_jobs}";
+ say "Latency: $stats->{latency}";
}
sub _worker {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment