Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the filter and aggregate query in stats call with subqueries … #133

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/Minion/Backend/Pg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,17 @@ sub stats {
my $self = shift;

my $stats = $self->pg->db->query(
"SELECT COUNT(*) FILTER (WHERE state = 'inactive' AND (expires IS NULL OR expires > NOW())) AS inactive_jobs,
COUNT(*) FILTER (WHERE state = 'active') AS active_jobs, COUNT(*) FILTER (WHERE state = 'failed') AS failed_jobs,
COUNT(*) FILTER (WHERE state = 'finished') AS finished_jobs,
COUNT(*) FILTER (WHERE state = 'inactive' AND delayed > NOW()) AS delayed_jobs,
"SELECT
(SELECT COUNT(*) FROM minion_jobs WHERE state = 'inactive' AND (expires IS NULL OR expires > NOW())) AS inactive_jobs,
(SELECT COUNT(*) FROM minion_jobs WHERE state = 'active') AS active_jobs,
(SELECT COUNT(*) FROM minion_jobs WHERE state = 'failed') AS failed_jobs,
(SELECT COUNT(*) FROM minion_jobs WHERE state = 'finished') AS finished_jobs,
(SELECT COUNT(*) FROM minion_jobs WHERE state = 'inactive' AND delayed > NOW()) AS delayed_jobs,
(SELECT COUNT(*) FROM minion_locks WHERE expires > NOW()) AS active_locks,
COUNT(DISTINCT worker) FILTER (WHERE state = 'active') AS active_workers,
(SELECT COUNT(DISTINCT worker) FROM minion_jobs mj WHERE state = 'active') AS active_workers,
(SELECT CASE WHEN is_called THEN last_value ELSE 0 END FROM minion_jobs_id_seq) AS enqueued_jobs,
(SELECT COUNT(*) FROM minion_workers) AS workers,
EXTRACT(EPOCH FROM NOW() - PG_POSTMASTER_START_TIME()) AS uptime
FROM minion_jobs"
EXTRACT(EPOCH FROM NOW() - PG_POSTMASTER_START_TIME()) AS uptime"
)->hash;
$stats->{inactive_workers} = $stats->{workers} - $stats->{active_workers};

Expand Down
Loading