Add (ai gen)

This commit is contained in:
2023-10-02 00:22:13 +08:00
parent 274e11193d
commit 2b55e0376e
3 changed files with 109 additions and 21 deletions

View File

@@ -4,6 +4,8 @@
use App\Jobs\ShopeeSellerTopProductScraperJob;
use App\Models\Category;
use App\Models\DailyTaskSchedule;
use App\Models\ShopeeSellerCategory;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -14,29 +16,49 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// Schdule MY TECH Category
$category = Category::where('country_locale_slug','my')->where('name','Technology')->first();
// Schedule MY TECH Category
if (!is_null($category))
{
$hour = rand(0, 23);
$minute = rand(0, 59);
$schedule->call(function () use ($category) {
$shopee_seller_category = \App\Models\ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) {
$query->whereNull('last_ai_written_at')
->orWhere('last_ai_written_at', '=', \App\Models\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')
->onConnection('default');
})->dailyAt("{$hour}:{$minute}");
}
$schedule->call(function () {
$category = Category::where('country_locale_slug','my')->where('name','Technology')->first();
if (!is_null($category))
{
$task = $category->country_locale_slug . "-" . $category->slug;
$nextRun = DailyTaskSchedule::where('task', $task)->first();
if (!is_null($nextRun))
{
$currentTime = now()->toTimeString();
if ($currentTime == $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();
$task = ShopeeSellerTopProductScraperJob::dispatch($shopee_seller_category->seller, $category->country_locale->country_iso, $category)
->onQueue('default')
->onConnection('default');
// Update the next random run time for the following day using Eloquent
$nextRun->next_run_time = now()->addMinutes(rand(1200, 1440))->toTimeString();
$nextRun->save();
}
}
}
else
{
$nextRun = new DailyTaskSchedule;
$nextRun->task = 'my-technology';
$nextRun->next_run_time = now()->addMinutes(rand(0, 1440))->toTimeString();
$nextRun->save();
}
})->everyMinute();
}
/**
@@ -51,3 +73,5 @@ protected function commands(): void
}