Add (ai gen)

This commit is contained in:
2023-10-02 10:17:41 +08:00
parent 6942d9f4fb
commit d0271b4657
2 changed files with 17 additions and 17 deletions

View File

@@ -26,33 +26,33 @@ protected function schedule(Schedule $schedule)
{ {
$task = $category->country_locale_slug . "-" . $category->slug; $task = $category->country_locale_slug . "-" . $category->slug;
$nextRun = DailyTaskSchedule::where('task', $task)->first(); $nextRun = DailyTaskSchedule::where('task', $task)->first();
if (!is_null($nextRun)) if (!is_null($nextRun))
{ {
$currentTime = now()->format('H:i:00'); $currentTime = now();
if ($currentTime == $nextRun->next_run_time) {
$shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) { if ($currentTime->equalTo($nextRun->next_run_time)) {
$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) $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) {
->onQueue('default') $query->whereNull('last_ai_written_at')
->onConnection('default'); ->orWhere('last_ai_written_at', '=', ShopeeSellerCategory::whereNotNull('last_ai_written_at')->orderBy('last_ai_written_at', 'asc')->value('last_ai_written_at'));
})->first();
// Update the next random run time for the following day using Eloquent $task = ShopeeSellerTopProductScraperJob::dispatch($shopee_seller_category->seller, $category->country_locale->country_iso, $category)
$nextRun->next_run_time = now()->addMinutes(rand(1200, 1440))->format('H:i:00'); ->onQueue('default')
$nextRun->save(); ->onConnection('default');
}
// Update the next random run time for the following day using Eloquent
$nextRun->next_run_time = now()->addMinutes(rand(1200, 1440));
$nextRun->save();
}
} }
else else
{ {
$nextRun = new DailyTaskSchedule; $nextRun = new DailyTaskSchedule;
$nextRun->task = 'my-technology'; $nextRun->task = 'my-technology';
$nextRun->next_run_time = now()->addMinutes(rand(0, 1440))->format('H:i:00'); $nextRun->next_run_time = now()->addMinutes(rand(0, 1440));
$nextRun->save(); $nextRun->save();
} }
} }

View File

@@ -14,7 +14,7 @@ public function up(): void
Schema::create('daily_task_schedules', function (Blueprint $table) { Schema::create('daily_task_schedules', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('task'); $table->string('task');
$table->time('next_run_time'); $table->timestamp('next_run_time');
$table->timestamps(); $table->timestamps();
}); });
} }