Skip to content

Commit

Permalink
♻️ refactor prometheus functions (#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Feb 29, 2024
1 parent 6b0610b commit 9a7033c
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions app/Providers/PrometheusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public function register() {
}


public static function getJobsByDisplayName($table_name): array {
$counts = DB::table($table_name)
public static function getJobsByDisplayName(string $tableName): array {
$counts = DB::table($tableName)
->get(["queue", "payload"])
->map(fn($row) => [
'queue' => $row->queue,
Expand All @@ -169,20 +169,7 @@ public static function getJobsByDisplayName($table_name): array {
->toArray();

return array_map(
fn($job_properties, $count) => [$count, explode(PROM_JOB_SCRAPER_SEPARATOR, $job_properties)],
array_keys($counts),
array_values($counts)
);
}

public static function getJobsByQueue($table_name): array {
$counts = DB::table($table_name)
->get("queue")
->countBy(fn($job) => $job->queue)
->toArray();

return array_map(
fn($jobname, $count) => [$count, [$jobname]],
fn($jobProperties, $count) => [$count, explode(PROM_JOB_SCRAPER_SEPARATOR, $jobProperties)],
array_keys($counts),
array_values($counts)
);
Expand Down

0 comments on commit 9a7033c

Please sign in to comment.