mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-28 00:44:04 +00:00
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\V2;
|
|
|
|
|
|
use App\Classes\Jobs\Commands\V2\YD\FetchByTrakingNoYdPortalV2CommandJob;
|
|
use App\Classes\ValueObjects\Constants\PackingListType;
|
|
use App\Models\PackingList;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ProcessYDByTrakingNoDataV2Command extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'process-yd-by-traking-no-data-command';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Process data from YD Portal by traking no';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$jobs = $this->fetchByTrakingNoYdPortalV2CommandJob();
|
|
|
|
foreach ($jobs as $index => $job) {
|
|
$delayInSeconds = intdiv($index, 2);
|
|
dispatch($job)->delay(now()->addSeconds($delayInSeconds));
|
|
}
|
|
}
|
|
|
|
private function fetchByTrakingNoYdPortalV2CommandJob(){
|
|
$jobs = [];
|
|
|
|
$maxFetchTime = Carbon::now()->subMonths(4);
|
|
$packingLists = PackingList::where('type', PackingListType::SHIPPING_PACKING_LIST)->whereDate('created_at', '>=', $maxFetchTime)->get();
|
|
$count = 0;
|
|
foreach ($packingLists as $packingList) {
|
|
$jobs[] = new FetchByTrakingNoYdPortalV2CommandJob($packingList);
|
|
Log::info('Dispatched FetchByTrakingNoYdPortalV2CommandJob for packingList with id ' . $packingList->id . ' reference ' . $packingList->reference . ' created_at ' . $packingList->created_at);
|
|
$count++;
|
|
}
|
|
Log::info('Total FetchByTrakingNoYdPortalV2CommandJob dispatched: ' . $count);
|
|
|
|
return $jobs;
|
|
}
|
|
}
|