You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.4 KiB
PHP
87 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Helper\Sts\Indokargo;
|
|
use App\Models\StsLog;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Http\Request;
|
|
|
|
class StsReschedule extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'sts:reschedule';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Resschedule failed sts to sts data';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): void {
|
|
$sleep = 30; // 30 second
|
|
while(true) {
|
|
$this->info('---------------------------');
|
|
$this->info('reschedule sts:' . Carbon::now()->toDateTimeString());
|
|
$this->info('---------------------------');
|
|
|
|
// get reschedu;e sts logs
|
|
$success = 0;
|
|
$failed = 0;
|
|
$rescheduleStsLogs = StsLog::where(['is_retry' => true])->get();
|
|
foreach($rescheduleStsLogs as $rescheduleStsLog) {
|
|
try {
|
|
$partner = $rescheduleStsLog->partner;
|
|
$module = $rescheduleStsLog->module;
|
|
$serviceName = $rescheduleStsLog->service_name;
|
|
$request = new Request((array) $rescheduleStsLog->request_data ?? []);
|
|
$localId = $rescheduleStsLog->local_id;
|
|
$partnerId = $rescheduleStsLog->partner_id;
|
|
$lastSeq = $rescheduleStsLog->seq;
|
|
|
|
if($partner == StsLog::PARTNER_INDOKARGO) {
|
|
if($module == StsLog::MODULE_TV) {
|
|
if($serviceName == StsLog::SERVICE_CREATE_TV_ADDRESS) {
|
|
Indokargo::createTVAddress($request, $localId, $lastSeq);
|
|
} else if($serviceName == StsLog::SERVICE_UPDATE_TV_ADDRESS) {
|
|
Indokargo::updateTVAddress($request, $localId, $partnerId, $lastSeq);
|
|
} else if($serviceName == StsLog::SERVICE_CHANGE_STATUS_TV_ADDRESS) {
|
|
Indokargo::changeStatusAddress($request, $localId, $partnerId, $lastSeq);
|
|
} else {
|
|
throw new \Exception("Service name '$partner' > '$module' > '$serviceName' not found service");
|
|
}
|
|
} else {
|
|
throw new \Exception("Module name '$partner' > '$module' not found service");
|
|
}
|
|
} else {
|
|
throw new \Exception("Partner name '$partner' not found service");
|
|
}
|
|
$success++;
|
|
} catch(\Throwable $th) {
|
|
$failed++;
|
|
$this->info("stsLog id: ". $rescheduleStsLog->id . " => " . $th->getMessage());
|
|
}
|
|
}
|
|
|
|
// save all retry request is retry false
|
|
$rescheduleStsLogIds = $rescheduleStsLogs->pluck('id')->toArray();
|
|
StsLog::whereIn('id', $rescheduleStsLogIds)->update(['is_retry' => false]);
|
|
|
|
$this->info('---------------------------');
|
|
$this->info("result: $success success, $failed failed" );
|
|
$this->info("Sleep in $sleep seconds" );
|
|
$this->info('---------------------------');
|
|
sleep($sleep);
|
|
}
|
|
}
|
|
}
|