44
55use HoudaSlassi \Vantage \Models \VantageJob ;
66use HoudaSlassi \Vantage \Support \QueueDepthChecker ;
7+ use HoudaSlassi \Vantage \Support \VantageLogger ;
78use Illuminate \Http \Request ;
89use Illuminate \Routing \Controller ;
910use Illuminate \Support \Facades \DB ;
@@ -145,7 +146,7 @@ public function index(Request $request)
145146 try {
146147 $ queueDepths = QueueDepthChecker::getQueueDepthWithMetadataAlways ();
147148 } catch (\Throwable $ e ) {
148- Log ::warning ('Failed to get queue depths ' , ['error ' => $ e ->getMessage ()]);
149+ VantageLogger ::warning ('Failed to get queue depths ' , ['error ' => $ e ->getMessage ()]);
149150 // Always show at least one queue entry even on error
150151 $ queueDepths = [
151152 'default ' => [
@@ -252,27 +253,69 @@ public function jobs(Request $request)
252253 }
253254
254255 // Advanced tag filtering
255- if ($ request ->filled ('tags ' )) {
256- $ tags = is_array ($ request ->tags ) ? $ request ->tags : explode (', ' , $ request ->tags );
256+ $ tagsParam = $ request ->get ('tags ' );
257+
258+ // Check if tags parameter exists and is not empty
259+ if (!empty ($ tagsParam ) && trim ($ tagsParam ) !== '' ) {
260+ $ tags = is_array ($ tagsParam ) ? $ tagsParam : explode (', ' , $ tagsParam );
257261 $ tags = array_map ('trim ' , $ tags );
258262 $ tags = array_map ('strtolower ' , $ tags );
259-
260- if ($ request ->filled ('tag_mode ' ) && $ request ->tag_mode === 'any ' ) {
261- // Jobs that have ANY of the specified tags
262- $ query ->where (function ($ q ) use ($ tags ) {
263+ $ tags = array_filter ($ tags ); // Remove empty tags
264+
265+ if (!empty ($ tags )) {
266+ // Get database driver for database-specific JSON queries
267+ $ connectionName = (new VantageJob )->getConnectionName ();
268+ $ connection = DB ::connection ($ connectionName );
269+ $ driver = $ connection ->getDriverName ();
270+
271+ if ($ request ->filled ('tag_mode ' ) && $ request ->tag_mode === 'any ' ) {
272+ // Jobs that have ANY of the specified tags
273+ $ query ->where (function ($ q ) use ($ tags , $ driver ) {
274+ foreach ($ tags as $ tag ) {
275+ if ($ driver === 'sqlite ' ) {
276+ // SQLite: Use JSON functions if available, otherwise fallback to LIKE
277+ // Try json_each first (SQLite 3.38+), fallback to LIKE pattern
278+ $ q ->orWhereRaw ("EXISTS (
279+ SELECT 1 FROM json_each(job_tags)
280+ WHERE json_each.value = ?
281+ ) " , [json_encode ($ tag )]);
282+ } else {
283+ // MySQL and PostgreSQL support whereJsonContains
284+ $ q ->orWhereJsonContains ('job_tags ' , $ tag );
285+ }
286+ }
287+ });
288+ } else {
289+ // Jobs that have ALL of the specified tags (default)
263290 foreach ($ tags as $ tag ) {
264- $ q ->orWhereJsonContains ('job_tags ' , $ tag );
291+ if ($ driver === 'sqlite ' ) {
292+ // SQLite: Use JSON functions if available
293+ $ query ->whereRaw ("EXISTS (
294+ SELECT 1 FROM json_each(job_tags)
295+ WHERE json_each.value = ?
296+ ) " , [json_encode ($ tag )]);
297+ } else {
298+ // MySQL and PostgreSQL
299+ $ query ->whereJsonContains ('job_tags ' , $ tag );
300+ }
265301 }
266- });
267- } else {
268- // Jobs that have ALL of the specified tags (default)
269- foreach ($ tags as $ tag ) {
270- $ query ->whereJsonContains ('job_tags ' , $ tag );
271302 }
272303 }
273304 } elseif ($ request ->filled ('tag ' )) {
274305 // Single tag filter (backward compatibility)
275- $ query ->whereJsonContains ('job_tags ' , strtolower ($ request ->tag ));
306+ $ tag = strtolower (trim ($ request ->tag ));
307+ $ connectionName = (new VantageJob )->getConnectionName ();
308+ $ connection = DB ::connection ($ connectionName );
309+ $ driver = $ connection ->getDriverName ();
310+
311+ if ($ driver === 'sqlite ' ) {
312+ $ query ->whereRaw ("EXISTS (
313+ SELECT 1 FROM json_each(job_tags)
314+ WHERE json_each.value = ?
315+ ) " , [json_encode ($ tag )]);
316+ } else {
317+ $ query ->whereJsonContains ('job_tags ' , $ tag );
318+ }
276319 }
277320
278321 if ($ request ->filled ('since ' )) {
@@ -285,7 +328,16 @@ public function jobs(Request $request)
285328 ->withQueryString ();
286329
287330 // Get filter options
288- $ queues = VantageJob::distinct ()->pluck ('queue ' )->filter ();
331+ // Only show queues that actually have jobs in vantage_jobs table
332+ // This ensures filtering by a queue will return results
333+ $ queues = VantageJob::distinct ()
334+ ->whereNotNull ('queue ' )
335+ ->where ('queue ' , '!= ' , '' )
336+ ->pluck ('queue ' )
337+ ->filter ()
338+ ->sort ()
339+ ->values ();
340+
289341 $ jobClasses = VantageJob::distinct ()->pluck ('job_class ' )->map (fn ($ c ) => class_basename ($ c ))->filter ();
290342
291343 // Get all available tags with counts
@@ -434,7 +486,7 @@ public function retry($id)
434486 return back ()->with ('success ' , "✓ Job queued for retry! " );
435487
436488 } catch (\Throwable $ e ) {
437- \Log ::error ('Vantage: Retry failed ' , [
489+ VantageLogger ::error ('Vantage: Retry failed ' , [
438490 'job_id ' => $ id ,
439491 'error ' => $ e ->getMessage ()
440492 ]);
@@ -460,22 +512,22 @@ protected function restoreJobFromPayload(VantageJob $run): ?object
460512 $ serialized = $ payload ['raw_payload ' ]['data ' ]['command ' ] ?? null ;
461513
462514 if (!$ serialized ) {
463- \Log ::warning ('Vantage: No serialized command in payload ' , ['run_id ' => $ run ->id ]);
515+ VantageLogger ::warning ('Vantage: No serialized command in payload ' , ['run_id ' => $ run ->id ]);
464516 return null ;
465517 }
466518
467519 // Unserialize it - Laravel stored it this way originally
468520 $ job = unserialize ($ serialized , ['allowed_classes ' => true ]);
469521
470522 if (!is_object ($ job )) {
471- \Log ::warning ('Vantage: Unserialize did not return object ' , [
523+ VantageLogger ::warning ('Vantage: Unserialize did not return object ' , [
472524 'run_id ' => $ run ->id ,
473525 'result_type ' => gettype ($ job )
474526 ]);
475527 return null ;
476528 }
477529
478- \Log ::info ('Vantage: Successfully restored job ' , [
530+ VantageLogger ::info ('Vantage: Successfully restored job ' , [
479531 'run_id ' => $ run ->id ,
480532 'job_class ' => get_class ($ job )
481533 ]);
0 commit comments