Add (ai gen)
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
use App\Jobs\ShopeeSellerTopProductScraperJob;
|
use App\Jobs\ShopeeSellerTopProductScraperJob;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
use App\Models\DailyTaskSchedule;
|
||||||
|
use App\Models\ShopeeSellerCategory;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@@ -14,29 +16,49 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
// Schdule MY TECH Category
|
// Schedule MY TECH Category
|
||||||
$category = Category::where('country_locale_slug','my')->where('name','Technology')->first();
|
|
||||||
|
|
||||||
if (!is_null($category))
|
$schedule->call(function () {
|
||||||
{
|
|
||||||
$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}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$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
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
35
app/Models/DailyTaskSchedule.php
Normal file
35
app/Models/DailyTaskSchedule.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DailyTaskSchedule
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property string $task
|
||||||
|
* @property Carbon $next_run_time
|
||||||
|
* @property Carbon|null $created_at
|
||||||
|
* @property Carbon|null $updated_at
|
||||||
|
*
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class DailyTaskSchedule extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'daily_task_schedules';
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'next_run_time' => 'datetime'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'task',
|
||||||
|
'next_run_time'
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('daily_task_schedules', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('task');
|
||||||
|
$table->time('next_run_time');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('daily_task_schedules');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user