From 51f035c0a2db734a97229d621cc14bbf0f40438f Mon Sep 17 00:00:00 2001 From: charlesteh <39686678+charlesteh@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:22:18 +0800 Subject: [PATCH] update (kernel): fix pickup logic --- app/Console/Kernel.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index baa94a2..c5467e5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -34,10 +34,16 @@ protected function schedule(Schedule $schedule) if ($currentTime->gte($nextRun->next_run_time)) { - $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) { - $query->whereNull('last_ai_written_at') - ->orWhere('last_ai_written_at', '=', ShopeeSellerCategory::whereNotNull('last_ai_written_at')->orderBy('last_ai_written_at', 'asc')->value('last_ai_written_at')); - })->first(); + $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id) + ->orderByRaw('ISNULL(last_ai_written_at) DESC') + ->orderBy('last_ai_written_at', 'asc') + ->orderBy('id', 'asc') + ->first(); + + // $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) { + // $query->whereNull('last_ai_written_at') + // ->orWhere('last_ai_written_at', '=', ShopeeSellerCategory::whereNotNull('last_ai_written_at')->orderBy('last_ai_written_at', 'asc')->value('last_ai_written_at')); + // })->first(); $task = ShopeeSellerTopProductScraperJob::dispatch($shopee_seller_category->seller, $category->country_locale->country_iso, $category) ->onQueue('default')