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