Update (kernel): add more schedulers
This commit is contained in:
@@ -16,11 +16,19 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
// Schedule MY TECH Category
|
$this->scheduleCategory($schedule, 'my', 'Technology', 'gen:my-technology');
|
||||||
|
$this->scheduleCategory($schedule, 'my', 'Fitness', 'gen:my-fitness');
|
||||||
|
$this->scheduleCategory($schedule, 'my', 'Home & Living', 'gen:my-home-living');
|
||||||
|
}
|
||||||
|
|
||||||
$schedule->call(function () {
|
/**
|
||||||
|
* Schedule a category.
|
||||||
|
*/
|
||||||
|
private function scheduleCategory(Schedule $schedule, $locale, $categoryName, $taskName)
|
||||||
|
{
|
||||||
|
$schedule->call(function () use ($locale, $categoryName) {
|
||||||
|
|
||||||
$category = Category::where('country_locale_slug','my')->where('name','Technology')->first();
|
$category = Category::where('country_locale_slug', $locale)->where('name', $categoryName)->first();
|
||||||
|
|
||||||
if (!is_null($category))
|
if (!is_null($category))
|
||||||
{
|
{
|
||||||
@@ -40,16 +48,10 @@ protected function schedule(Schedule $schedule)
|
|||||||
->orderBy('id', 'asc')
|
->orderBy('id', 'asc')
|
||||||
->first();
|
->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)
|
$task = ShopeeSellerTopProductScraperJob::dispatch($shopee_seller_category->seller, $category->country_locale->country_iso, $category)
|
||||||
->onQueue('default')
|
->onQueue('default')
|
||||||
->onConnection('default');
|
->onConnection('default');
|
||||||
|
|
||||||
// Update the next random run time for the following day using Eloquent
|
|
||||||
$nextRun->next_run_time = now()->addMinutes(rand(1200, 1440));
|
$nextRun->next_run_time = now()->addMinutes(rand(1200, 1440));
|
||||||
$nextRun->save();
|
$nextRun->save();
|
||||||
}
|
}
|
||||||
@@ -57,15 +59,13 @@ protected function schedule(Schedule $schedule)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$nextRun = new DailyTaskSchedule;
|
$nextRun = new DailyTaskSchedule;
|
||||||
$nextRun->task = 'my-technology';
|
$nextRun->task = $category->country_locale_slug . "-" . $category->slug;
|
||||||
$nextRun->next_run_time = now()->addMinutes(rand(0, 1440));
|
$nextRun->next_run_time = now()->addMinutes(rand(0, 1440));
|
||||||
$nextRun->save();
|
$nextRun->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
})->everyMinute()->name($taskName);
|
||||||
})->everyMinute();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,8 +77,4 @@ protected function commands(): void
|
|||||||
|
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user