public function fire($job, $data) { $keyID = $data['keyID']; $vCode = $data['vCode']; $job_record = \SeatQueueInformation::where('jobID', '=', $job->getJobId())->first(); // Check that we have a valid jobid if (!$job_record) { // Sometimes the jobs get picked up faster than the submitter could write a // database entry about it. So, just wait 5 seconds before we come back and // try again $job->release(5); return; } // We place the actual API work in our own try catch so that we can report // on any critical errors that may have occurred. // By default Laravel will requeue a failed job based on --tries, but we // dont really want failed api jobs to continually poll the API Server try { $job_record->status = 'Working'; $job_record->save(); $job_record->output = 'Started AccountBalance Update'; $job_record->save(); EveApi\Corporation\AccountBalance::Update($keyID, $vCode); $job_record->output = 'Started ContactList Update'; $job_record->save(); EveApi\Corporation\ContactList::Update($keyID, $vCode); $job_record->output = 'Started Contracts Update'; $job_record->save(); EveApi\Corporation\Contracts::Update($keyID, $vCode); $job_record->output = 'Started CorporationSheet Update'; $job_record->save(); EveApi\Corporation\CorporationSheet::Update($keyID, $vCode); $job_record->output = 'Started CustomsOffice Update'; $job_record->save(); EveApi\Corporation\CustomsOffices::Update($keyID, $vCode); $job_record->output = 'Started IndustryJobs Update'; $job_record->save(); EveApi\Corporation\IndustryJobs::Update($keyID, $vCode); $job_record->output = 'Started KillMails Update'; $job_record->save(); EveApi\Corporation\KillMails::Update($keyID, $vCode); $job_record->output = 'Started MarketOrders Update'; $job_record->save(); EveApi\Corporation\MarketOrders::Update($keyID, $vCode); $job_record->output = 'Started Medals Update'; $job_record->save(); EveApi\Corporation\Medals::Update($keyID, $vCode); $job_record->output = 'Started MemberMedals Update'; $job_record->save(); EveApi\Corporation\MemberMedals::Update($keyID, $vCode); $job_record->output = 'Started MemberSecurity Update'; $job_record->save(); EveApi\Corporation\MemberSecurity::Update($keyID, $vCode); $job_record->output = 'Started MemberSecurityLog Update'; $job_record->save(); EveApi\Corporation\MemberSecurityLog::Update($keyID, $vCode); $job_record->output = 'Started MemberTracking Update'; $job_record->save(); EveApi\Corporation\MemberTracking::Update($keyID, $vCode); $job_record->output = 'Started Shareholders Update'; $job_record->save(); EveApi\Corporation\Shareholders::Update($keyID, $vCode); $job_record->output = 'Started Standings Update'; $job_record->save(); EveApi\Corporation\Standings::Update($keyID, $vCode); $job_record->output = 'Started StarbaseList Update'; $job_record->save(); EveApi\Corporation\StarbaseList::Update($keyID, $vCode); $job_record->output = 'Started StarbaseDetail Update'; $job_record->save(); EveApi\Corporation\StarbaseDetail::Update($keyID, $vCode); $job_record->output = 'Started Titles Update'; $job_record->save(); EveApi\Corporation\Titles::Update($keyID, $vCode); $job_record->status = 'Done'; $job_record->output = null; $job_record->save(); $job->delete(); } catch (\Seat\EveApi\Exception\APIServerDown $e) { // The API Server is down according to \Seat\EveApi\bootstrap(). // Due to this fact, we can simply take this job and put it // back in the queue to be processed later. $job_record->status = 'Queued'; $job_record->output = 'The API Server appears to be down. Job has been re-queued.'; $job_record->save(); // Re-queue the job to try again in 10 minutes $job->release(60 * 10); } catch (\Exception $e) { $job_record->status = 'Error'; $job_record->output = 'Last status: ' . $job_record->output . PHP_EOL . 'Error: ' . $e->getCode() . ': ' . $e->getMessage() . PHP_EOL . 'File: ' . $e->getFile() . ':' . $e->getLine() . PHP_EOL . 'Trace: ' . $e->getTraceAsString() . PHP_EOL . 'Previous: ' . $e->getPrevious(); $job_record->save(); $job->delete(); } }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'Titles'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $title_list = $pheal->corpScope->Titles(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $title_list->cached_until, $corporationID)) { foreach ($title_list->titles as $title) { $title_data = \EveCorporationTitlemap::where('corporationID', '=', $corporationID)->where('titleID', '=', $title->titleID)->first(); if (!$title_data) { $title_info = new \EveCorporationTitlemap(); } else { $title_info = $title_data; } $title_info->corporationID = $corporationID; $title_info->titleID = $title->titleID; $title_info->titleName = $title->titleName; $title_info->roles = Titles::getRolesFromRolegroup($title->roles); $title_info->grantableRoles = Titles::getRolesFromRolegroup($title->grantableRoles); $title_info->rolesAtHQ = Titles::getRolesFromRolegroup($title->rolesAtHQ); $title_info->grantableRolesAtHQ = Titles::getRolesFromRolegroup($title->grantableRolesAtHQ); $title_info->rolesAtBase = Titles::getRolesFromRolegroup($title->rolesAtBase); $title_info->grantableRolesAtBase = Titles::getRolesFromRolegroup($title->grantableRolesAtBase); $title_info->rolesAtOther = Titles::getRolesFromRolegroup($title->rolesAtOther); $title_info->grantableRolesAtOther = Titles::getRolesFromRolegroup($title->grantableRolesAtOther); $title_info->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $title_list->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $title_list; }