updated several jobs. removed the task for starting and stoppinig jobs. just seems to be unnecessary data

This commit is contained in:
2021-01-17 22:52:35 +09:00
parent 23b78d709f
commit 997e6a9cde
46 changed files with 663 additions and 499 deletions

View File

@@ -7,7 +7,7 @@ use DB;
use Log;
//Job
use App\Jobs\ProcessAssetsJob;
use App\Jobs\Commands\Structures\ProcessAssetsJob;
//Library
use App\Library\Esi\Esi;
@@ -48,49 +48,13 @@ class GetAssetsCommand extends Command
*/
public function handle()
{
$assets = null;
$pages = 0;
//Create the command helper container
$task = new CommandHelper('GetAssets');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Setup the esi authentication container
$config = config('esi');
ProcessAssetsJob::dispatch($charId, $corpId)->onQueue('assets');
//Declare some variables
$charId = $config['primary'];
$corpId = 98287666;
//ESI Scope Check
$esiHelper = new Esi();
$assetScope = $esiHelper->HaveEsiScope($config['primary'], 'esi-assets.read_corporation_assets.v1');
if($assetScope == false) {
Log::critical("Scope check for esi-assets.read_corporation_assets.v1 failed.");
return null;
}
//Get the refresh token from the database
$token = $esiHelper->GetRefreshToken($charId);
//Create the authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
try {
$assets = $esi->page(1)
->invoke('get', '/corporations/{corporation_id}/assets/', [
'corporation_id' => $corpId,
]);
} catch (RequestFailedException $e) {
Log::critical("Failed to get asset list.");
return null;
}
$pages = $assets->pages;
for($i = 1; $i <= $pages; $i++) {
ProcessAssetsJob::dispatch($charId, $corpId, $i)->onQueue('assets');
}
$task->SetStopStatus();
}
}

View File

@@ -5,13 +5,10 @@ namespace App\Console\Commands\Data;
//Internal Library
use Illuminate\Console\Command;
//Library
use Commands\Library\CommandHelper;
//Models
use App\Models\Structure\Structure;
use App\Models\Structure\Service;
use App\Models\Stock\Asset;
use App\Models\Structure\Asset;
class EmptyJumpBridges extends Command
{
@@ -46,16 +43,8 @@ class EmptyJumpBridges extends Command
*/
public function handle()
{
$task = new CommandHelper('EmptyJumpBridges');
//Add entry into the table saying the job is starting
$task->SetStartStatus();
Structure::truncate();
Service::truncate();
Asset::truncate();
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -4,7 +4,6 @@ namespace App\Console\Commands\Data;
//Internal Library
use Illuminate\Console\Command;
use Commands\Library\CommandHelper;
//Models
use App\Models\Corporation\AllianceCorp;
@@ -47,11 +46,6 @@ class GetCorpsCommand extends Command
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('CorpJournal');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Declare some variables
$esiHelper = new Esi;
@@ -82,8 +76,5 @@ class GetCorpsCommand extends Command
$entry->name = $corpInfo->name;
$entry->save();
}
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -4,11 +4,6 @@ namespace App\Console\Commands\Data;
//Internal Library
use Illuminate\Console\Command;
use Carbon\Carbon;
use Log;
//Library
use Commands\Library\CommandHelper;
//Jobs
use App\Jobs\Commands\Moons\PurgeMoonLedgerJob;
@@ -46,11 +41,6 @@ class PurgeCorpMoonLedgers extends Command
*/
public function handle()
{
$task = new CommandHelper('PurgeCorpLedgers');
$task->SetStartStatus();
PurgeMoonLedgerJob::dispatch();
$task->SetStopStatus();
}
}

View File

@@ -3,10 +3,8 @@
namespace App\Console\Commands\Eve;
use Illuminate\Console\Command;
use Log;
//Library
use Commands\Library\CommandHelper;
use App\Library\Moons\MoonCalc;
//Job
@@ -45,14 +43,9 @@ class ItemPricesUpdateCommand extends Command
*/
public function handle()
{
$task = new CommandHelper('ItemPriceUpdate');
$task->SetStartStatus();
$moonHelper = new MoonCalc;
$moonHelper->FetchNewPrices();
//ItemPricesUpdateJob::dispatch()->onQueue('default');
$task->SetStopStatus();
}
}

View File

@@ -3,13 +3,11 @@
namespace App\Console\Commands\Finances;
use Illuminate\Console\Command;
use Log;
use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper;
//Jobs
use App\Jobs\ProcessWalletJournalJob;
use App\Jobs\Commands\Finances\ProcessWalletJournalJob;
class HoldingFinancesCommand extends Command
{
@@ -44,12 +42,6 @@ class HoldingFinancesCommand extends Command
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('HoldingFinances');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Setup the Finances container
$finance = new FinanceHelper();
@@ -71,8 +63,5 @@ class HoldingFinancesCommand extends Command
for($i = 1; $i <= $pages; $i++) {
ProcessWalletJournalJob::dispatch(6, $config['primary'], $i)->onQueue('journal');
}
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -3,13 +3,12 @@
namespace App\Console\Commands\Finances;
use Illuminate\Console\Command;
use Log;
use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper;
//Jobs
use App\Jobs\ProcessWalletJournalJob;
use App\Jobs\Commands\Finances\ProcessWalletJournalJob;
//Models
use App\Models\Esi\EsiToken;
@@ -71,14 +70,7 @@ class SovBillsCommand extends Command
$sovBill = new SovBillExpenses;
$esiHelper = new Esi;
$finance = new FinanceHelper();
$lookup = new LookupHelper;
//Create the command helper container
$task = new CommandHelper('SovBills');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
$lookup = new LookupHelper;
//Get the esi configuration
$config = config('esi');
@@ -125,8 +117,5 @@ class SovBillsCommand extends Command
}
}
}
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -1,10 +1,10 @@
<?php
namespace App\Console\Commands\Mining;
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MiningTaxesCommand extends Command
class MiningTaxesInvoices extends Command
{
/**
* The name and signature of the console command.

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MiningTaxesLedgers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
return 0;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MiningTaxesObservers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
return 0;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MiningTaxesPayments extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
return 0;
}
}

View File

@@ -5,15 +5,11 @@ namespace App\Console\Commands\Moons;
//Internal Library
use Illuminate\Console\Command;
use Carbon\Carbon;
use Log;
//Jobs
use App\Jobs\Commands\Moons\FetchMoonLedgerJob;
use App\Jobs\Commands\Moons\FetchMoonObserverJob;
//Library
use Commands\Library\CommandHelper;
//Models
use App\Models\Esi\EsiScope;
@@ -54,11 +50,6 @@ class MoonsUpdateCommand extends Command
$delay = 0;
$characters = array();
//Create the new command helper container
$task = new CommandHelper('MoonsUpdateCommand');
//Set the task start status
$task->SetStartStatus();
//Get all of the characters who have registered structures for moon ledgers
$miningChars = EsiScope::where([
'scope' => 'esi-industry.read_corporation_mining.v1',
@@ -83,8 +74,5 @@ class MoonsUpdateCommand extends Command
//Fetch all of the corp ledgers with the job dispatch
FetchMoonLedgerJob::dispatch($charId);
}
//Set task done status
$task->SetStopStatus();
}
}

View File

@@ -4,12 +4,8 @@ namespace App\Console\Commands\RentalMoons;
//Internal Library
use Illuminate\Console\Command;
use Log;
use Carbon\Carbon;
//Library
use Commands\Library\CommandHelper;
//Jobs
use App\Jobs\Commands\RentalMoons\SendMoonRentalPaymentReminderJob;
use App\Jobs\Commands\RentalMoons\UpdateMoonRentalPaidState;
@@ -47,17 +43,10 @@ class AllianceRentalMoonInvoiceCreationCommand extends Command
*/
public function handle()
{
//Set the task as started
$task = new CommandHelper('AllianceRentalInvoice');
$task->SetStartStatus();
//Send the job for the invoice creation command
SendMoonRentalPaymentReminderJob::dispatch()->delay(Carbon::now()->addSeconds(10));
//Update the paid state for the moons
UpdateMoonRentalPaidState::dispatch()->delay(Carbon::now()->addSeconds(600));
//Set the task as stopped
$task->SetStopStatus();
}
}

View File

@@ -4,10 +4,6 @@ namespace App\Console\Commands\RentalMoons;
//Internal Library
use Illuminate\Console\Command;
use Log;
//Library
use Commands\Library\CommandHelper;
//Job
use App\Jobs\Commands\RentalMoons\UpdateMoonRentalPrice;
@@ -45,12 +41,6 @@ class AllianceRentalMoonUpdatePricingCommand extends Command
*/
public function handle()
{
//Setup the task handler
$task = new CommandHelper('AllianceRentalMoonPriceUpdater');
$task->SetStartStatus();
UpdateMoonRentalPrice::dispatch();
$task->SetStopStatus();
}
}

View File

@@ -3,22 +3,9 @@
namespace App\Console\Commands\Structures;
use Illuminate\Console\Command;
use Log;
//Library
use App\Library\Structures\StructureHelper;
use App\Library\Esi\Esi;
use Commands\Library\CommandHelper;
use Seat\Eseye\Exceptions\RequestFailedException;
//Job
use App\Jobs\ProcessStructureJob;
//Models
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\Structure\Structure;
use App\Models\Structure\Service;
use App\Jobs\Commands\Structures\ProcessStructureJob;
class GetStructuresCommand extends Command
{
@@ -53,69 +40,14 @@ class GetStructuresCommand extends Command
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('GetStructures');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Get the esi config
$config = config('esi');
//Declare some variables
$charId = $config['primary'];
$corpId = 98287666;
$sHelper = new StructureHelper($charId, $corpId);
$structures = null;
//ESI Scope Check
$esiHelper = new Esi;
$structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1');
$corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1');
//Check scopes
if($structureScope == false || $corpStructureScope == false) {
if($structureScope == false) {
Log::critical("Scope check for esi-universe.read_structures.v1 has failed.");
}
if($corpStructureScope == false) {
Log::critical("Scope check for esi-corporations.read_structures.v1 has failed.");
}
return null;
}
//Get the refresh token from the database
$token = $esiHelper->GetRefreshToken($charId);
//Create the esi authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
//Set the current page
$currentPage = 1;
//Set our default total pages, and we will refresh this later
$totalPages = 1;
//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;
}
//Get the total number of pages of all the structures
$totalPages = $structures->pages;
//Truncate the structures and the structure services in order to prepare to put new structures in the database
Structure::truncate();
Service::truncate();
for($i = 1; $i <= $totalPages; $i++) {
ProcessStructureJob::dispatch($charId, $corpId, $currentPage)->onQueue('structures');
}
//Mark the job as finished
$task->SetStopStatus();
//Dispatch the job to be done when the application has time
ProcessStructureJob::dispatch($charId, $corpId);
}
}

View File

@@ -7,10 +7,7 @@ use Illuminate\Console\Command;
use Carbon\Carbon;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
//Library
use Command\Library\CommandHelper;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
//Models
use App\Models\Rentals\RentalSystem;
@@ -49,11 +46,6 @@ class SystemRentalCommand extends Command
*/
public function handle()
{
//Create the new command helper container
$task = new CommandHelper('SystemRentalMailer');
//Add the entry into the jobs table saying the job has started
$task->SetStartStatus();
//Create other variables
$body = null;
$delay = 30;
@@ -104,10 +96,6 @@ class SystemRentalCommand extends Command
//After the mail is dispatched, save the sent mail record
$this->SaveSentRecord($config['primary'], $subject, $body, (int)$contact->contact_id, 'character');
}
//Mark the job as finished
$task->SetStopStatus();
}
private function TotalizeCost($systems) {

View File

@@ -16,7 +16,7 @@ use App\Models\Contracts\SupplyChainBid;
use App\Models\Contracts\SupplyChainContract;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
class SupplyChainController extends Controller
{

View File

@@ -9,7 +9,7 @@ use Log;
use Carbon\Carbon;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
//Library Helpers
use App\Library\Lookups\LookupHelper;

View File

@@ -25,7 +25,7 @@ use App\Library\Esi\Esi;
use App\Library\Lookups\LookupHelper;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
class MoonsAdminController extends Controller
{

View File

@@ -23,7 +23,7 @@ use App\Library\Moons\MoonCalc;
use App\Library\Lookups\LookupHelper;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
class MoonsController extends Controller
{

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Jobs;
namespace App\Jobs\Commands\Eve;
//Internal Library
use Illuminate\Bus\Queueable;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Jobs;
namespace App\Jobs\Commands\Finances;
//Internal Libraries
use Illuminate\Bus\Queueable;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Jobs\Commands\Mining;
namespace App\Jobs\Commands\MiningTaxes;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Jobs\Commands\Mining;
namespace App\Jobs\Commands\MiningTaxes;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Jobs\Commands\Mining;
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -8,7 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ProcessMiningTaxesInvoiceJob implements ShouldQueue
class FetchMiningTaxesLedgersJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

View File

@@ -1,21 +1,14 @@
<?php
namespace App\Jobs;
namespace App\Jobs\Commands\MiningTaxes;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
//App Library
use App\Library\Structures\StructureHelper;
//App Models
use App\Models\Jobs\JobStatus;
class ProcessStructureJob implements ShouldQueue
class FetchMiningTaxesObserversJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -28,6 +21,8 @@ class ProcessStructureJob implements ShouldQueue
/**
* Number of job retries
*
* @var int
*/
public $tries = 3;
@@ -36,18 +31,16 @@ class ProcessStructureJob implements ShouldQueue
*/
private $charId;
private $corpId;
private $page;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($charId, $corpId, $page)
public function __construct($charId, $corpId)
{
$this->charId = $charId;
$this->corpId = $corpId;
$this->page = $page;
//Set the connection for the job
$this->connection = 'redis';
@@ -55,24 +48,30 @@ class ProcessStructureJob implements ShouldQueue
/**
* 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.
* The job's duty is to get all of the corporation's moon mining observers,
* then store them in the database.
*
* @return void
*/
public function handle()
{
//Declare variables
$sHelper = new StructureHelper($this->charId, $this->corpId);
$structures = $sHelper->GetStructuresByPage($this->page);
/**
* Remove the current observers from the database.
*/
foreach($structures as $structure) {
$sHelper->ProcessStructure($structure);
}
/**
* Create the esi call to get the current observers
*/
//After the job is completed, delete the job
$this->delete();
/**
* Add the current observers in the database
*/
/**
* Cleanup
*/
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Jobs\Commands\MiningTaxes;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class MailMiningTaxesInvoiceJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Jobs\Commands\MiningTaxes;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ProcessMiningTaxesPaymentsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@@ -15,7 +15,7 @@ use Carbon\Carbon;
use App\Library\Lookups\LookupHelper;
//Jobs
use App\Jobs\ProcessSendEvveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
//Models
use App\Models\MoonRentals\AllianceRentalMoon;

View File

@@ -18,7 +18,7 @@ use App\Library\Lookups\LookupHelper;
use App\Models\MoonRentals\AllianceRentalMoon;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
class UpdateMoonRentalPaidState implements ShouldQueue
{

View File

@@ -0,0 +1,150 @@
<?php
namespace App\Jobs\Commands\Structures;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Log;
//App Library
use App\Library\Structures\StructureHelper;
use App\Jobs\Library\JobHelper;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Assets\AssetHelper;
//App Models
use App\Models\Jobs\JobStatus;
use App\Models\Structure\Asset;
class ProcessAssetsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 3600;
/**
* Number of job retries
*/
public $tries = 3;
/**
* Job Variables
*/
private $charId;
private $corpId;
private $page;
private $esi;
private $currentPage;
private $totalPages;
private $config;
protected $location_array = [
'StructureFuel',
'FighterBay',
];
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($charId, $corpId, $page)
{
//Set the connection for the job
$this->connection = 'redis';
$this->charId = $charId;
$this->corpId = $corpId;
$this->currentPage = 1;
$this->totalPages = 1;
$this->config = config('esi');
}
/**
* Execute the job.
* The job's task is to get all of the information for all of the assets in
* a structure and store them in the database. This task can take a few seconds
* therefore we want the Horizon job queue to take care of the request rather
* than the cronjob.
*
* @return void
*/
public function handle()
{
//Declare variables
$esiHelper = new Esi;
$aHelper = new AssetHelper($this->charId, $this->corpId);
//ESI Scope Check
$assetScope = $esiHelper->HaveEsiScope($this->config['primary'], 'esi-assets.read_corporation_assets.v1');
if($assetScope == false) {
Log::critical("Scope check for esi-assets.read_corporations_assets.v1 has failed in ProcessAssetsJob");
return null;
}
//Truncate the Asset data from the table
//Get the refresh token from the database
$token = $esiHelper->GetRefreshToken($this->charId);
//Create the authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
try {
$assets = $esi->page($this->currentPage)
->invoke('get', '/corporations/{corporation_id}/assets/', [
'corporation_id' => $this->corpId,
]);
} catch(RequestFailedException $e) {
Log::critical("Failed to get asset list in ProcessAssetsJob");
return null;
}
//Set the total number of pages
$this->totalPages = $assets->pages;
//Do this while the total pages is not completed
do {
if($currentPage > 1) {
try {
$assets = $esi->page($this->currentPage)
->invoke('get', '/corporations/{corporation_id}/assets/', [
'corporation_id' => $this->corpId,
]);
} catch(RequestFailedException $e) {
Log::critical("Failed to get asset list on page " . $this->currentPage . " in ProcessAssetsJob");
return null;
}
}
//Cycle through the assets, and attempt to store them.
foreach($assets as $asset) {
//if the asset is in one of the locations we want, then store
//or update the asset
if(in_array($asset->location_flag, $this->location_array)) {
//Attempt to store the asset
$aHelper->StoreNewAsset($asset);
}
}
//Increment the current page before doing the loop again
$this->currentPage++;
} while($this->currentPage <= $this->totalPages);
//Once all the data is stored and updated, purge stale data
$aHelper->PurgeStaleData();
}
}

View File

@@ -0,0 +1,143 @@
<?php
namespace App\Jobs\Commands\Structures;
//Internal Library
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Log;
//App Library
use App\Library\Structures\StructureHelper;
use App\Library\Esi\Esi;
use Seat\Eseye\Exceptions\RequestionFailedException;
//App Models
use App\Models\Jobs\JobStatus;
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\Structure\Structure;
use App\Models\Structure\Service;
class ProcessStructureJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 3600;
/**
* Number of job retries
*/
public $tries = 3;
/**
* Job Variables
*/
private $charId;
private $corpId;
private $totalPages;
private $currentPage;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($charId, $corpId)
{
//Set the connection for the job
$this->connection = 'redis';
$this->charId = $charId;
$this->corpId = $corpId;
$this->currentPage = 1;
$this->totalPages = 1;
}
/**
* 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 variables
$config = config('esi');
$sHelper = new StructureHelper($this->charId, $this->corpId);
$structures = null;
//ESI Scope Check
$esiHelper = new Esi;
$structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1');
$corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1');
//Check scopes
if($structureScope == false || $corpStructureScope == false) {
if($structureScope == false) {
Log::critical("Scope check for esi-universe.read_structures.v1 has failed.");
}
if($corpStructureScope == false) {
Log::critical("Scope check for esi-corporations.read_structures.v1 has failed.");
}
return null;
}
//Get the refresh token from the database
$token = $esiHelper->GetRefreshToken($this->charId);
//Create the esi authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
//Attempt to get the ESI data
try {
$structures = $esi->page($this->currentPage)
->invoke('get', '/corporations/{corporation_id}/structures/', [
'corporation_id' => $this->corpId,
]);
} catch (RequestFailedException $e) {
Log::critical("Failed to get structure list in ProcessStructureJob");
return null;
}
$this->totalPages = $structures->pages;
//Truncate the structures and the structure services in order to add the latest data
Structure::truncate();
Service::truncate();
do {
if($this->currentPage > 1) {
try {
$structures = $esi->page($this->currentPage)
->invoke('get', '/corporations/{corporation_id}/structures/', [
'corporation_id' => $this->corpId,
]);
} catch(RequestFailedException $e) {
Log::critical("Failed to get structure list on page" . $this->currentPage . " in ProcessStructureJob.");
return null;
}
}
//For each set of data, process the data
foreach($structures as $structure) {
$sHelper->ProcessStructure($structure);
}
//Increment the current page
$this->currentPage++;
} while($this->currentPage <= $this->totalPages);
//After the job is completed, delete the job
$this->delete();
}
}

View File

@@ -18,7 +18,7 @@ use App\Models\Contracts\SupplyChainBid;
use App\Models\Contracts\SupplyChainContract;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
class EndSupplyChainContractJob implements ShouldQueue
{

View File

@@ -1,100 +0,0 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Log;
//App Library
use App\Library\Structures\StructureHelper;
use App\Jobs\Library\JobHelper;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Assets\AssetHelper;
//App Models
use App\Models\Jobs\JobStatus;
use App\Models\Stock\Asset;
class ProcessAssetsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 3600;
/**
* Number of job retries
*/
public $tries = 3;
/**
* Job Variables
*/
private $charId;
private $corpId;
private $page;
private $esi;
protected $location_array = [
'StructureFuel',
'FighterBay',
];
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($charId, $corpId, $page)
{
$this->charId = $charId;
$this->corpId = $corpId;
$this->page = $page;
//Set the connection for the job
$this->connection = 'redis';
}
/**
* Execute the job.
* The job's task is to get all fo the information for all of the assets in
* a structure and store them in the database. This task can take a few seconds
* therefore we want the Horizon job queue to take care of the request rather
* than the cronjob.
*
* @return void
*/
public function handle()
{
//Declare the asset helper
$aHelper = new AssetHelper($this->charId, $this->corpId, $this->page);
//Get a page of assets
$assets = $aHelper->GetAssetsByPage();
//Cycle through the assets, and attmept to store them.
foreach($assets as $asset) {
//If the asset is in one of the locations we want, then store
//or update the asset
if(in_array($asset->location_flag, $this->location_array)) {
//Attempt to store the asset
$aHelper->StoreNewAsset($asset);
}
}
//Purge Stale Data
$aHelper->PurgeStaleData();
}
}

View File

@@ -13,24 +13,22 @@ use Seat\Eseye\Exceptions\RequestFailedException;
//Models
use App\Models\Jobs\JobStatus;
use App\Models\Stock\Asset;
use App\Models\Structure\Asset;
class AssetHelper {
private $charId;
private $corpId;
private $page;
public function __construct($char, $corp, $pg = null) {
public function __construct($char, $corp) {
$this->charId = $char;
$this->corpId = $corp;
$this->page = $pg;
}
}
/**
* Get Assets By Page in order to store in the database
*/
public function GetAssetsByPage() {
public function GetAssetsByPage($page) {
//Declare the variable for the esi helper
$esiHelper = new Esi;

View File

@@ -10,7 +10,7 @@ use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
//Seat Stuff
use Seat\Eseye\Cache\NullCache;

View File

@@ -1,24 +0,0 @@
<?php
namespace App\Models\Eve;
use Illuminate\Database\Eloquent\Model;
class EveRegion extends Model
{
//Table Name
protected $table = 'eve_regions';
//Timestamps
public $timestamps = false;
/**
* Variables which are mass assignable
*
* @var array
*/
protected $fillable = [
'region_id',
'region_name',
];
}

View File

@@ -1,35 +0,0 @@
<?php
namespace App\Models\Market;
use Illuminate\Database\Eloquent\Model;
class MarketRegionOrder extends Model
{
//Table Name
protected $table = 'market_region_orders';
//Timestamps
public $timestamps = true;
/**
* Items which are mass assignable
*
* @var array
*/
protected $fillable = [
'region_id',
'duration',
'is_buy_order',
'issued',
'location_id',
'min_volume',
'order_id',
'price',
'range',
'system_id',
'type_id',
'volume_remain',
'volume_total',
];
}

View File

@@ -6,5 +6,24 @@ use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
//
//Table Name
protected $table = 'alliance_mining_tax_invoices';
//Timestamps
public $timestamps = true;
/**
* Items which are mass assignable
*
* @var array
*/
protected $fillable = [
'character_id',
'character_name',
'invoice_id',
'invoice_amount',
'date_issued',
'date_due',
'status',
];
}

View File

@@ -6,5 +6,22 @@ use Illuminate\Database\Eloquent\Model;
class Ledger extends Model
{
//
//Table Name
protected $table = 'alliance_mining_tax_ledgers';
//Timestamps
public $timestamps = true;
/**
* Items which are mass assignable
*
* @var array
*/
protected $fillable = [
'character_id',
'last_updated',
'type_id',
'ore_name',
'quantity',
];
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models\MiningTax;
use Illuminate\Database\Eloquent\Model;
class Observer extends Model
{
//Table Name
protected $table = 'alliance_mining_tax_observers';
//Timestamps
public $timestamps = true;
/**
* Items which are mass assignable
*
* @var array
*/
protected $fillable = [
'last_updated',
'observer_id',
'observer_type',
];
}

View File

@@ -6,5 +6,24 @@ use Illuminate\Database\Eloquent\Model;
class Payment extends Model
{
//
//Table Name
protected $table = 'alliance_mining_tax_payments';
//Timestamps
public $timestamps = true;
/**
* Items which are mass assignable
*
* @var array
*/
protected $fillable = [
'character_id',
'character_name',
'invoice_id',
'invoice_amount',
'payment_amount',
'payment_date',
'status',
];
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Stock;
namespace App\Models\Structure;
use Illuminate\Database\Eloquent\Model;

View File

@@ -1,39 +0,0 @@
<?php
namespace App\Models\Wormholes;
use Illuminate\Database\Eloquent\Model;
class AllianceWormhole extends Model
{
//Table Name
public $table = 'alliance_wormholes';
//Timestamps
public $timestamps = true;
//Primary Key
public $primaryKey = 'id';
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'system',
'sig_id',
'duration_left',
'dateTime',
'class',
'type',
'hole_size',
'stability',
'details',
'link',
'mass_allowed',
'individual_mass',
'regeneration',
'max_stable_time',
];
}

View File

@@ -1,31 +0,0 @@
<?php
namespace App\Models\Wormholes;
use Illuminate\Database\Eloquent\Model;
class WormholeType extends Model
{
//Table Name
public $table = 'wormhole_types';
//Timestamps
public $timestamps = false;
//Primary Key
public $primaryKey = 'id';
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'type',
'leads_to',
'mass_allowed',
'individual_mass',
'regeneration',
'max_stable_time',
];
}

View File

@@ -15,16 +15,53 @@ class CreateMiningTaxTables extends Migration
{
Schema::create('alliance_mining_tax_invoices', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('character_id');
$table->string('character_name');
$table->unsignedBigInteger('invoice_id');
$table->float('invoice_amount');
$table->dateTime('date_issued');
$table->dateTime('date_due');
$table->enum('status', [
'Pending',
'Paid',
'Late',
'Paid Late',
'Deferred',
]);
$table->timestamps();
});
Schema::create('alliance_mining_tax_observers', function (Blueprint $table) {
$table->id();
$table->dateTime('last_updated');
$table->unsignedBigInteger('observer_id');
$table->string('observer_type');
$table->timestamps();
});
Schema::create('alliance_mining_tax_ledgers', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('character_id');
$table->dateTime('last_updated');
$table->unsignedBigInteger('type_id');
$table->string('ore_name');
$table->unsignedBigInteger('quantity');
$table->timestamps();
});
Schema::create('alliance_mining_tax_payments', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('character_id');
$table->string('character_name');
$table->unsignedBigInteger('invoice_id');
$table->float('invoice_amount');
$table->float('payment_amount');
$table->dateTime('payment_date');
$table->enum('status', [
'Pending',
'Accepted',
'Rejected',
]);
$table->timestamps();
});
}