process structure job

This commit is contained in:
2019-05-28 02:07:23 -05:00
parent b2d60b70f0
commit c5039c3152
6 changed files with 225 additions and 38 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ class GetStructures extends Command
//Setup the esi authentication container
$config = config('esi');
//Get the refresh token from the database
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
$token = EsiToken::where(['character_id' => 93738489])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
+104 -3
View File
@@ -16,28 +16,129 @@ use App\Jobs\Library\JobHelper;
//App Models
use App\Models\Jobs\JobProcessStructure;
use App\Models\Job\JobStatus;
use App\Models\Structure\Structure;
class ProcessStructureJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 300;
/**
* Number of job retries
*/
public $tries = 3;
/**
* Job Variables
*/
private $charId;
private $corpId;
private $structure;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
public function __construct(JobProcessStructure $jps)
{
//
$this->charId = $jps->charId;
$this->corpId = $jps->corpId;
$this->structure = $jps->structure;
//Set the connection for the job
$this->connection = 'redis';
}
/**
* Execute the job.
* The job's task is to get all of the information for a particular structure
* and store it in the database. This task can take a few seconds because of the ESI
* calls required to store the information. We leave this type of job up to the queue
* in order to take the load off of the cron job.
*
* @return void
*/
public function handle()
{
//
//Declare the structure helper class.
$structureHelper = new StructureHelper();
//Using our private function make sure we have the necessrary ESI scope
if($this->HasEsiScope() == false) {
Log::critical("Job couldn't be completed because of ESI Scopes.");
return null;
}
//Setup the Eseye container and authenticate it.
$config = config('esi');
$token = EsiToken::where(['character_id' => 93738489])->get(['refresh_token']);
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'];
'secret' => $config['secret'];
'refresh_token' => $token[0]->refresh_token;
]);
//Declare the esi variable
$esi = new Eseye($authentication);
try {
$info = $esi->invoke('get', '/universe/structures/{structure_id}/', [
'structure_id' => $this->structure['structure_id'],
]);
} catch(RequestFailedException $e) {
return null;
}
//Record the structure information into the database
//Find if the structure exists
$found = Structure::where(['structure_id' => $this->structure['structure_id']])->get();
if($found) {
} else {
$structure = new Structure;
$structure->structure_id = $this->structure['structure_id'];
$structure->structure_name = $info['name'];
$structure->corporation_id = $info['owner_id'];
$structure->solar_system_id = $info['solar_system_id'];
if(isset($info['type_id'])) {
$structure->type_id = $info['type_id'];
}
$structure->position_x = $info['position']['x'];
$structure->position_y = $info['position']['y'];
$structure->position_z = $info['position']['z'];
$structure->fuel_expires = $this->structure['fuel_expires'];
$structure->next_reinforce_apply = $this->structure['']
}
//Record the structure's services information into the database
}
private function DecodeDate($date) {
$esiHelper = new Esi();
$dateTime = $esiHelper->DecodeDate($date);
return $dateTime;
}
private function HasEsiScope() {
$esiHelper = new Esi();
$universe = $esi->HaveEsiScope($this->charId, 'esi-universe.read_structures.v1');
if($universe == true) {
return true;
} else {
return false;
}
}
}
@@ -0,0 +1,47 @@
<?php
/**
* W4RP Services
* GNU Public License
*/
namespace App\Library\Stock\Helper;
//Internal Library
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
//Job
use App\Jobs\ProcessStocksJob;
//Library
use App\Library\Esi\Esi;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
//Models
use App\Models\Stock\StructureStock;
class StructureStockHelper {
private $scopeCheck;
public function __construct() {
$esi = new Esi();
$assetScope = $esi->HaveEsiScope($charId, 'esi-assets.read_corporation_assets.v1');
$structureScope = $esi->HaveEsiScope($charId, 'esi-universe.read_structurs.v1');
if($assetScope == false || $structureScope == false) {
$scopeCheck = false;
} else {
$scopeCheck = true;
}
}
}
?>
-34
View File
@@ -1,34 +0,0 @@
<?php
namespace App\Models\Stock;
use Illuminate\Database\Eloquent\Model;
class Structure extends Model
{
/**
* Requires the scope:
* esi-universe.read_structures.v1
*/
//Table Name
public $table = '';
//Timestamps
public $timestamps = false;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'name',
'owner_id',
'position_x',
'position_y',
'position_z',
'solar_system_id',
'type_id',
];
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Models\Structure;
use Illuminate\Database\Eloquent\Model;
class Service extends Model
{
//Table Name
public $table = 'structure_services';
//Timestamps
public $timestamps = false;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'structure_id',
'name',
'state',
];
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Models\Structure;
use Illuminate\Database\Eloquent\Model;
class Structure extends Model
{
/**
* Requires the scope:
* esi-universe.read_structures.v1
*/
//Table Name
public $table = 'structures';
//Timestamps
public $timestamps = false;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'structure_id',
'structure_name',
'solar_system_id',
'solar_system_name',
'type_id',
'corporation_id',
'services', //True or false on whether it has services which are held in a different table
'state'
'state_timer_start',
'state_timer_end',
'fuel_expires',
'profile_id',
'position_x',
'position_y',
'position_z',
'next_reinforce_apply',
'next_reinforce_hour',
'next_reinforce_weekday',
'reinforce_hour',
'reinforce_weekday',
'unanchors_at',
];
}