Skip to content

Commit

Permalink
Add config option to order queued but not started jobs first
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-MyAnaPro authored and romanzipp committed May 2, 2024
1 parent a06a41a commit 86cb0e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/queue-monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
];
16 changes: 16 additions & 0 deletions src/Controllers/ShowQueueMonitorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 86cb0e4

Please sign in to comment.