update the job

This commit is contained in:
2025-02-17 10:51:46 +03:30
parent fb5233144f
commit edee575b56

View File

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Jobs\SendRoadObservationToNikarayan;
use App\Models\RoadObserved;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class SendRoadObservationToNikarayanCommand extends Command
@@ -28,19 +29,26 @@ class SendRoadObservationToNikarayanCommand extends Command
*/
public function handle(): void
{
$this->info("Dispatching jobs with 2 seconds delay between each...");
$count = 0;
$this->info("Dispatching jobs with a 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) {
$road->update(['rms_status' => 1]);
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)");
}
});
DB::transaction(function () use ($count) {
$delay = 0;
RoadObserved::query()
->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-13 23:59:59'])
->where('rms_status', '=', 0)
->chunk(50, function ($roads) use ($delay, $count) {
foreach ($roads as $road) {
$road->update(['rms_status' => 1]);
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addMinutes(10)->addSeconds($delay));
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with a {$delay} seconds delay.");
$this->info("Scheduled job for Road ID: {$road->id} {$delay}s");
$delay += 3;
$count +=1;
}
});
});
$this->info("all item's sent successfully");
$this->info("{$count} item's sent successfully");
}
}