From 86cb0e49da4ecc566199e7d258126425626cce76 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sun, 28 Apr 2024 18:09:28 +0200 Subject: [PATCH] Add config option to order queued but not started jobs first --- config/queue-monitor.php | 3 +++ src/Controllers/ShowQueueMonitorController.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/config/queue-monitor.php b/config/queue-monitor.php index 7733f78..dbe9eb2 100644 --- a/config/queue-monitor.php +++ b/config/queue-monitor.php @@ -53,5 +53,8 @@ // The interval before refreshing the dashboard (in seconds). 'refresh_interval' => null, + + // Order the queued but not started jobs first + 'order_queued_first' => false ], ]; diff --git a/src/Controllers/ShowQueueMonitorController.php b/src/Controllers/ShowQueueMonitorController.php index 259f05a..57e3c42 100644 --- a/src/Controllers/ShowQueueMonitorController.php +++ b/src/Controllers/ShowQueueMonitorController.php @@ -54,6 +54,22 @@ public function __invoke(Request $request) $jobsQuery->where('data', 'like', "%{$filters['custom_data']}%"); } + if (config('queue-monitor.ui.order_queued_first')) { + $connection = DB::connection(); + + if ($connection instanceof DatabaseConnections\MySqlConnection) { + $jobsQuery->orderByRaw('-`started_at`'); + } + + if ($connection instanceof DatabaseConnections\SqlServerConnection) { + $jobsQuery->orderByRaw('(CASE WHEN [started_at] IS NULL THEN 0 ELSE 1 END)'); + } + + if ($connection instanceof DatabaseConnections\SQLiteConnection) { + $jobsQuery->orderByRaw('started_at DESC NULLS FIRST'); + } + } + $jobsQuery ->orderBy('started_at', 'desc') ->orderBy('started_at_exact', 'desc');