fetch rental moon ledger and observer updates along with starting moon rental invoice job. up next is moon rental payment job.

This commit is contained in:
2020-05-10 05:11:50 -05:00
parent 8e93eececf
commit 40e18ccb7a
4 changed files with 51 additions and 29 deletions

View File

@@ -59,6 +59,7 @@ class FetchRentalMoonLedgerJob implements ShouldQueue
$lookup = new LookupHelper;
$response = null;
$structureInfo = null;
$entries = array();
//Get the configuration for the main site
$config = config('esi');
@@ -105,21 +106,31 @@ class FetchRentalMoonLedgerJob implements ShouldQueue
//Get the corporation information
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
$newLedger = new RentalMoonLedger;
$newLedger->corporation_id = $corpId;
$newLedger->corporation_name = $corpName;
$newLedger->character_id = $ledger->character_id;
$newLedger->character_name = $charInfo->name;
$newLedger->observer_id = $observer->observer_id;
$newLedger->observer_name = $observerName;
$newLedger->type_id = $ledger->type_id;
$newLedger->ore = $ore;
$newLedger->quantity = $ledger->quantity;
$newLedger->recorded_corporation_id = $ledger->recorded_corporation_id;
$newLedger->recorded_corporation_name = $recordedCorpName;
$newLedger->last_updated = $ledger->last_updated;
$newLedger->save();
$entries[] = [
'corporation_id' => $corpId,
'corporation_name' => $corpName,
'character_id' => $ledger->character_id,
'character_name' => $charInfo->name,
'observer_id' => $observer->observer_id,
'observer_name' => $observerName,
'type_id' => $ledger->type_id,
'ore' => $ore,
'quantity' => $ledger->quantity,
'recorded_corporation_id' => $ledger->recorded_corporation_id,
'recorded_corporation_name' => $recordedCorpName,
'last_updated' => $ledger->last_updated,
'created_at' => $ledger->last_updated . ' 23:59:59',
'updated_at' => $ledger->last_updated . ' 23:59:59',
];
}
//Insert or ignore each of the records saved into the array through the foreach loop
RentalMoonLedger::insertOrIgnore($entries);
Log::info(
'FetchRentalMoonLedgerJob inserted up to ' .count($entires) . ' new ledger entries.'
);
}
}
}

View File

@@ -56,6 +56,7 @@ class FetchRentalMoonObserversJob implements ShouldQueue
//Declare some variables
$lookup = new LookupHelper;
$esi = new Esi;
$obss = array();
//Get the configuration for the main site
$config = config('esi');
@@ -83,21 +84,14 @@ class FetchRentalMoonObserversJob implements ShouldQueue
//Run through the mining observers, and add them to the database as needed
foreach($responses as $observer) {
RentalMoonObserver::where(['observer_id' => $observer->observer_id])->count();
//If the observer is not found, then add it to the database, otherwise we just need to update the last updated portion
if($count == 0) {
$obs = new RentalMoonObserver;
$obs->observer_id = $observer->observer_id;
$obs->observer_type = $observer->observer_type;
$obs->last_updated = $esi->DecodeDate($observer->last_updated);
$obs->save();
} else {
RentalMoonObserver::where([
'observer_id' => $observer->observer_id,
])->update([
'last_updated' => $esi->DecodeDate($observer->last_updated),
]);
}
//Populate the array with the data, so we can do an insert or ignore after the foreach loop is completed.
$obss[] = [
'observer_id' => $observer->observer_id,
'observer_type' => $observer->observer_type,
'last_updated' => $esi->DecodeDate($observer->last_updated)
];
}
RentalMoonObserver::insertOrIgnore($obss);
}
}

View File

@@ -11,6 +11,19 @@ use Illuminate\Foundation\Bus\Dispatchable;
class MoonRentalInvoiceJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 3600;
/**
* Retries
*
* @var int
*/
public $retries = 3;
/**
* Create a new job instance.

View File

@@ -23,4 +23,8 @@ class RentalMoonObserver extends Model
'observer_type',
'last_updated',
];
public function ledger() {
return $this->hasMany('App\Models\Moon\RentalMoonLedger', 'observer_id', 'observer_id');
}
}