diff --git a/app/Console/Commands/GetStructures.php b/app/Console/Commands/GetStructures.php index 1c80e82bc..308955464 100644 --- a/app/Console/Commands/GetStructures.php +++ b/app/Console/Commands/GetStructures.php @@ -105,37 +105,26 @@ class GetStructuresCommand extends Command //Set our default total pages, and we will refresh this later $totalPages = 1; - //Get the list of structures, and send for processing - do { - //Try to get the ESI data - try { - $structures = $esi->page($currentPage) - ->invoke('get', '/corporations/{corporation_id}/structures/', [ - 'corporation_id' => $corpId, - ]); - } catch (RequestFailedException $e) { - Log::critical("Failed to get structure list."); - return null; - } + //Try to get the ESI data + try { + $structures = $esi->page($currentPage) + ->invoke('get', '/corporations/{corporation_id}/structures/', [ + 'corporation_id' => $corpId, + ]); + } catch (RequestFailedException $e) { + Log::critical("Failed to get structure list."); + return null; + } - //Update the total pages to go through - if($totalPages == 1) { - $totalPages = $structures->pages; - } + $totalPages = $structures->pages; - //For each structure we retrieve dispatch a job to process it. - foreach($structures as $structure) { - $job = new JobProcessStructure; - $job->charId = $charId; - $job->corpId = $corpId; - $job->structure = $structure; - ProcessStructureJob::dispatch($job)->onQueue('structures'); - } - - //Update the page counter - $currentPage++; - //Check to see if we need to grab more pages or not. - } while($currentPage <= $totalPages); + for($i = 1; $i <= $totalPages; $i++) { + $job = new JobProcessStructure; + $job->charId = $charId; + $job->corpId = $corpId; + $job->page = $currentPage; + ProcessStructureJob::dispatch($job)->onQueue('structures'); + } //Mark the job as finished $task->SetStopStatus(); diff --git a/app/Jobs/ProcessStructureJob.php b/app/Jobs/ProcessStructureJob.php index 54d8dfc6f..dc596364f 100644 --- a/app/Jobs/ProcessStructureJob.php +++ b/app/Jobs/ProcessStructureJob.php @@ -38,8 +38,6 @@ class ProcessStructureJob implements ShouldQueue private $charId; private $corpId; private $page; - private $esi; - private $structure; /** * Create a new job instance. @@ -50,7 +48,7 @@ class ProcessStructureJob implements ShouldQueue { $this->charId = $jps->charId; $this->corpId = $jps->corpId; - $this->structure = $jps->structure; + $this->page = $jps->page; //Set the connection for the job $this->connection = 'redis'; @@ -69,7 +67,11 @@ class ProcessStructureJob implements ShouldQueue { $sHelper = new StructureHelper($this->charId, $this->corpId); - $sHelper->ProcessStructure($this->structure); + $structures = $sHelper->GetStructuresByPage($this->page); + + foreach($structures as $structure) { + $sHelper->ProcessStructure($structure); + } //After the job is completed, delete the job $this->delete(); diff --git a/app/Library/Structures/StructureHelper.php b/app/Library/Structures/StructureHelper.php index b175df950..0d7fa14a8 100644 --- a/app/Library/Structures/StructureHelper.php +++ b/app/Library/Structures/StructureHelper.php @@ -61,7 +61,18 @@ class StructureHelper { //Setup the ESI variable $esi = new Eseye($authentication); + //Try to get the ESI data + try { + $structures = $esi->page($currentPage) + ->invoke('get', '/corporations/{corporation_id}/structures/', [ + 'corporation_id' => $corpId, + ]); + } catch (RequestFailedException $e) { + Log::critical("Failed to get structure list."); + return null; + } + return $structures; } public function ProcessStructure($structure) { diff --git a/app/Models/Jobs/JobProcessStructure.php b/app/Models/Jobs/JobProcessStructure.php index 40e4b4da8..1d0cfc326 100644 --- a/app/Models/Jobs/JobProcessStructure.php +++ b/app/Models/Jobs/JobProcessStructure.php @@ -20,6 +20,6 @@ class JobProcessStructure extends Model protected $fillable = [ 'charId', 'corpId', - 'structure', + 'page', ]; }