-
-
Save anonymous/a9feac7241badf8edeb415e331289707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Minion/Backend/Pg.pm b/lib/Minion/Backend/Pg.pm | |
index 2676fdf..b540735 100644 | |
--- a/lib/Minion/Backend/Pg.pm | |
+++ b/lib/Minion/Backend/Pg.pm | |
@@ -147,21 +147,14 @@ sub retry_job { | |
sub stats { | |
my $self = shift; | |
- my $stats = $self->pg->db->query( | |
- "select state::text || '_jobs', count(*) from minion_jobs group by state | |
- union all | |
- select 'delayed_jobs', count(*) from minion_jobs | |
- where state = 'inactive' and delayed > now() | |
- union all | |
- select 'inactive_workers', count(*) from minion_workers | |
- union all | |
- select 'active_workers', count(distinct worker) from minion_jobs | |
- where state = 'active'" | |
- )->arrays->reduce(sub { $a->{$b->[0]} = $b->[1]; $a }, {}); | |
- $stats->{inactive_workers} -= $stats->{active_workers}; | |
- $stats->{"${_}_jobs"} ||= 0 for qw(inactive active failed finished); | |
- | |
- return $stats; | |
+ $self->pg->db->query( | |
+ "select json_object_agg(queue, ( | |
+ select jsonb_object_agg(state || '_jobs', ( | |
+ select count(*) from minion_jobs where state = states.state and queue = queues.queue | |
+ )) | |
+ from (select unnest(array['active', 'failed', 'finished', 'inactive']::minion_state[]) as state) as states | |
+ )) from (select distinct queue from minion_jobs) as queues" | |
+ )->expand->array->[0]; | |
} | |
sub unregister_worker { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment