create job for road observed problems
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\SendRoadObservationToNikarayan;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SendRoadObservationToNikarayanCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'road-observation:send-to-nikarayan';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'send road observation to nikarayan from 1 farvardin 1403 to 14 mehr 1403';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->info("Dispatching jobs with 2 seconds delay between each...");
|
||||
|
||||
RoadObserved::query()
|
||||
->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-14 23:59:59'])
|
||||
->chunk(50, function ($roads) {
|
||||
foreach ($roads as $road) {
|
||||
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addSeconds(2));
|
||||
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with 2 seconds delay.");
|
||||
$this->info("Scheduled job for Road ID: {$road->id} (Delay: 2s)");
|
||||
}
|
||||
});
|
||||
|
||||
$this->info("all item's sent successfully");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user