process wallet journal job which is a new job to make system faster for cron

This commit is contained in:
2019-05-03 22:54:29 -05:00
parent aefe83a49a
commit cc8da2f494
4 changed files with 205 additions and 22 deletions

View File

@@ -10,28 +10,12 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
//App Library
use App\Library\Finances\MarketTax;
use App\Library\Finances\PlayerDonation;
use App\Library\Finances\ReprocessingTax;
use App\Library\Finances\JumpBridgeTax;
use App\Library\Finances\StructureIndustryTax;
use App\Library\Finances\OfficeFee;
use App\Library\Finances\PlanetProductionTax;
use App\Library\Finances\PISale;
use App\Library\Lookups\LookupHelper;
use App\Library\Finances\Helper\FinanceHelper;
//App Models
use App\Models\User\UserToCorporation;
use App\Models\Finances\CorpMarketJournal;
use App\Models\Finances\JumpBridgeJournal;
use App\Models\Finances\OfficeFeesJournal;
use App\Models\Finances\PISaleJournal;
use App\Models\Finances\PlanetProductionTaxJournal;
use App\Models\Finances\PlayerDonationJournal;
use App\Models\Finances\REprocessingTaxJournal;
use App\Models\Finances\StructureIndustryTaxJournal;
use App\Models\Jobs\ProcessWalletJournalJob as JobModel;
class ProcessWalletJournal implements ShouldQueue
class ProcessWalletJournalJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -42,18 +26,32 @@ class ProcessWalletJournal implements ShouldQueue
*/
public $timeout = 600;
/**
* Connection to utilize
*
* @var string
*/
public $connection = 'database';
/**
* Delay time for job
*
* @var int
*/
public $delay = 15;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct() {
public function __construct(JobModel $pwj) {
$this->pwj = $pwj;
}
/**
* Execute the job.
* Utilized by using ProcessWalletJournal::dispatch()
* Utilized by using ProcessWalletJournalJob::dispatch()
* The model is passed into the dispatch function, then added to the queue
* for processing.
*
@@ -61,7 +59,13 @@ class ProcessWalletJournal implements ShouldQueue
*/
public function handle()
{
//Declare the class variable we need
$finance = new FinanceHelper();
$finance->GetWalletJournalPage($pwj->division, $pwj->charId, $pwj->page);
//After the job is completed, delete the job
$this->pwj->delete();
}
/**

View File

@@ -279,6 +279,122 @@ class FinanceHelper {
} while ($currentPage < $totalPages);
}
public function GetJournalPageCount($division, $charId) {
//Declare class variables
$lookups = new LookupHelper;
//Get the ESI refresh token for the corporation
$tokenData = $this->TokenInfo($charId);
$token = $tokenData['token'];
$scope = $tokdenData['scope'];
if($this->TokenNotFound($token, $scope)) {
return null;
}
//Refrence to see if the character is in our look up table for corporation and characters
$corpId = $lookups->LookupCharacter($charId);
//Create the ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Create the esi class variable
$esi = new Eseye($authentication);
$esi->setVersion('v4');
//Call the first page so we can get the header data for the number of pages
try {
$journals = $esi->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
'corporation_id' => $corpId,
'division' => $division,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
$pages = $journals->pages;
return $pages;
}
public function GetWalletJournalPage($division, $charId, $page = 1) {
//Declare new class variables
$market = new MarketTax();
$reprocessing = new ReprocessingTax();
$jb = new JumpBridgeTax();
$other = new PlayerDonation();
$industry = new StructureIndustryTax();
$office = new OfficeFee();
//Get the ESI refresh token for the corporation to add new wallet journals into the database
$tokenData = $this->TokenInfo($charId);
$token = $tokenData['token'];
$scope = $tokenData['scope'];
//Declare the lookup class helper
$lookups = new LookupHelper;
//If the token is not found, send the user an eve mail, and just exit out of the function
if($this->TokenNotFound($token, $scope)) {
return null;
}
//Reference to see if the character is in our look up table for corporations and characters
$corpId = $lookups->LookupCharacter($charId);
//Create an ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Create the esi class varialble
$esi = new Eseye($authentication);
$esi->setVersion('v4');
//Call the first page of the wallet journal, as we are always going to get at least one page.
//If we have more pages, then we will continue through the while loop.
try {
$journals = $esi->page($page)
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
'corporation_id' => $corpId,
'division' => $division,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
//Decode the wallet from json into an array
$wallet = json_decode($journals->raw, true);
//For each journal entry, attempt to store it in the database.
//The PutWalletJournal function checks to see if it's already in the database.
foreach($wallet as $entry) {
if($entry['amount'] > 0) {
if($entry['ref_type'] == 'brokers_fee') {
$market->InsertMarketTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'reprocessing_tax') {
$reprocessing->InsertReprocessingTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'structure_gate_jump') {
$jb->InsertJumpBridgeTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'player_donation' ||
($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) {
$other->InsertPlayerDonation($entry, $corpId, $division);
} else if($entry['ref_type'] == 'industry_job_tax' && $entry['second_party_id'] == 98287666) {
$industry->InsertStructureIndustryTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'office_rental_fee' && $entry['second_party_id'] == 98287666) {
$office->InsertOfficeFee($entry, $corpId, $division);
}
}
}
}
private function TokenInfo($charId) {
//Get the ESI refresh token for the corporation to add a new wallet jouranls into the database
//send the token and scope back to the calling function

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models\Jobs;
use Illuminate\Database\Eloquent\Model;
class ProcessWalletJournalJob extends Model
{
//Table Name
public $table = 'job_process_wallet_journal';
//Timestamps
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'charId',
'division',
'page',
];
}
?>

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class JobProcessWaletJournal extends Migration
{
/**
* Run the migration
*
* @return void
*/
public function up() {
if(!Schema::hasTable('job_process_wallet_journal')) {
Schema::create('job_process_wallet_journal', function(Blueprint $table) {
$table->increments('id')->unique();
$table->string('charId');
$table->string('division');
$table->integer('page');
$table->timestamps();
});
}
}
/**
* Reverse the migration
*
* @return void
*/
public function down() {
Schema::dropIfExists('job_process_wallet_journal');
}
}
?>