public function fire($job, $data) { $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->output = 'Started Teamspeak transfer'; $job_record->save(); $eveTransfer = new EveApi\Eve\TeamspeakTransfer(); $eveTransfer->Update(); \Log::info("done with TS update"); $job_record->status = 'Done'; $job_record->output = null; $job_record->save(); $job->delete(); } 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 addToQueue($queue, $ownerID, $vCode, $api, $scope) { // Prepare the auth array if ($vCode != null) { $auth = array('keyID' => $ownerID, 'vCode' => $vCode); } else { $auth = array(); } // Check the databse if there are jobs outstanding ie. they have the status // Queued or Working. If not, we will queue a new job, else just capture the // jobID and return that $jobID = \SeatQueueInformation::where('ownerID', '=', $ownerID)->where('api', '=', $api)->whereIn('status', array('Queued', 'Working'))->first(); // Check if the $jobID was found, else, queue a new job if (!$jobID) { $jobID = \Queue::push($queue, $auth); \SeatQueueInformation::create(array('jobID' => $jobID, 'ownerID' => $ownerID, 'api' => $api, 'scope' => $scope, 'status' => 'Queued')); } else { // To aid in potential capacity debugging, lets write a warning log entry so that a user // is able to see that a new job was not submitted \Log::warning('A new job was not submitted due a similar one still being outstanding. Details: ' . $jobID, array('src' => __CLASS__)); // Set the jobID to the ID from the database $jobID = $jobID->jobID; } return $jobID; }
public function fire($job, $data) { $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 RefTypes Update'; $job_record->save(); EveApi\Eve\RefTypes::Update(); $job_record->output = 'Started ErrorList Update'; $job_record->save(); EveApi\Eve\ErrorList::Update(); $job_record->output = 'Started ConquerableStationList Update'; $job_record->save(); EveApi\Eve\ConquerableStationList::Update(); $job_record->output = 'Started AllianceList Update'; $job_record->save(); EveApi\Eve\AllianceList::Update(); $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 function fire($job, $data) { $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 Starbase Fuel Check'; $job_record->save(); Notifications\Starbase\Fuel::Update(); $job_record->output = 'Started Starbase Status Check'; $job_record->save(); Notifications\Starbase\Status::Update(); $job_record->output = 'Started API Banned Calls Check'; $job_record->save(); Notifications\Api\BannedCall::Update(); $job_record->output = 'Started Key Check'; $job_record->save(); Notifications\Api\KeyCheck::Update(); $job_record->output = 'Started Corporation Member Check'; $job_record->save(); Notifications\Corporation\MemberInactivity::Update(); $job_record->status = 'Done'; $job_record->output = null; $job_record->save(); $job->delete(); } 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(); } }
/** * Execute the console command. * * @return mixed */ public function fire() { // Connect to the Redis backend using Predis $redis = new \Predis\Client(array('host' => \Config::get('database.redis.default.host'), 'port' => \Config::get('database.redis.default.port'))); // Count the amount of jobs in the queue by // issuing a Redis LRANGE command: // // http://redis.io/commands/LRANGE $redis_count = count($redis->lrange('queues:default', 0, -1)); $this->line('Redis reports ' . $redis_count . ' jobs in the queue (queues:default)'); // Get the Queued job count from the database $db_info = \SeatQueueInformation::where('status', '=', 'Queued')->count(); $this->line('The database reports ' . $db_info . ' queued jobs'); // If the amount of jobs in the redis queue does // not match that of the database, just warn // about this. if ($db_info != $redis_count) { $this->info('[!] The redis & db queued counts are not the same. This is not always a bad thing'); } // Get the Done job count frmo the database $db_info = \SeatQueueInformation::where('status', '=', 'Done')->count(); $this->line('The database reports ' . $db_info . ' done jobs'); // Get the Error job count from the database $db_info = \SeatQueueInformation::where('status', '=', 'Error')->count(); // If there are Error jobs, loop over them and // print the status details if ($db_info > 0) { $this->comment('Current error-state jobs (' . $db_info . '):'); foreach (\SeatQueueInformation::where('status', '=', 'Error')->get() as $row) { $this->line('OwnerID: ' . $row->ownerID . ' | Scope: ' . $row->scope . ' | API: ' . $row->api . ' | Status: "' . str_limit($row->output, 20, '...') . '" | Created: ' . Carbon::parse($row->created_at)->diffForHumans() . ' | Last updated: ' . Carbon::parse($row->updated_at)->diffForHumans()); } } else { $this->line('The database reports ' . $db_info . ' error jobs'); } // Get the Working jobs from the database $db_info = \SeatQueueInformation::where('status', '=', 'Working')->count(); if ($db_info > 0) { $this->comment('Current working-state jobs (' . $db_info . '):'); foreach (\SeatQueueInformation::where('status', '=', 'Working')->get() as $row) { $this->line('OwnerID: ' . $row->ownerID . ' | Scope: ' . $row->scope . ' | API: ' . $row->api . ' | Status: "' . $row->output . '" | Created: ' . Carbon::parse($row->created_at)->diffForHumans() . ' | Last updated: ' . Carbon::parse($row->updated_at)->diffForHumans()); } } else { $this->line('The database reports ' . $db_info . ' working jobs'); } }
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\Character\AccountBalance::Update($keyID, $vCode); $job_record->output = 'Started AssetList Update'; $job_record->save(); EveApi\Character\AssetList::Update($keyID, $vCode); $job_record->output = 'Started CharacterSheet Update'; $job_record->save(); EveApi\Character\CharacterSheet::Update($keyID, $vCode); $job_record->output = 'Started ContactList Update'; $job_record->save(); EveApi\Character\ContactList::Update($keyID, $vCode); $job_record->output = 'Started ContactNotifications Update'; $job_record->save(); EveApi\Character\ContactNotifications::Update($keyID, $vCode); $job_record->output = 'Started Contracts Update'; $job_record->save(); EveApi\Character\Contracts::Update($keyID, $vCode); $job_record->output = 'Started IndustryJobs Update'; $job_record->save(); EveApi\Character\IndustryJobs::Update($keyID, $vCode); $job_record->output = 'Started CharacterInfo Update'; $job_record->save(); EveApi\Character\Info::Update($keyID, $vCode); $job_record->output = 'Started KillMails Update'; $job_record->save(); EveApi\Character\KillMails::Update($keyID, $vCode); $job_record->output = 'Started MailMessages Update'; $job_record->save(); EveApi\Character\MailMessages::Update($keyID, $vCode); $job_record->output = 'Started MailingLists Update'; $job_record->save(); EveApi\Character\MailingLists::Update($keyID, $vCode); $job_record->output = 'Started Notifications Update'; $job_record->save(); EveApi\Character\Notifications::Update($keyID, $vCode); $job_record->output = 'Started PlanetaryColonies Update'; $job_record->save(); EveApi\Character\PlanetaryColonies::Update($keyID, $vCode); $job_record->output = 'Started MarketOrders Update'; $job_record->save(); EveApi\Character\MarketOrders::Update($keyID, $vCode); $job_record->output = 'Started Research Update'; $job_record->save(); EveApi\Character\Research::Update($keyID, $vCode); $job_record->output = 'Started SkillInTraining Update'; $job_record->save(); EveApi\Character\SkillInTraining::Update($keyID, $vCode); $job_record->output = 'Started SkillQueue Update'; $job_record->save(); EveApi\Character\SkillQueue::Update($keyID, $vCode); $job_record->output = 'Started Standings Update'; $job_record->save(); EveApi\Character\Standings::Update($keyID, $vCode); $job_record->output = 'Started UpcomingCalendarEvents Update'; $job_record->save(); EveApi\Character\UpcomingCalendarEvents::Update($keyID, $vCode); $job_record->output = 'Started WalletJournal Update'; $job_record->save(); EveApi\Character\WalletJournal::Update($keyID, $vCode); $job_record->output = 'Started WalletTransactions Update'; $job_record->save(); EveApi\Character\WalletTransactions::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(); } }
/** * Execute the console command. * * @return mixed */ public function fire() { // Log what we are going to do in the laravel.log file \Log::info('Started command ' . $this->name, array('src' => __CLASS__)); // Grab the 'Queued' or 'Working' jobs that we have record // of so that we can process a time related check on // them foreach (\SeatQueueInformation::where('status', 'Queued')->orWhere('status', 'Working')->get() as $job) { // We want to preserve the job status that we had for // some debugging reasons, so lets set the new // message added to it. $new_output = '60 Minute Job Runtime Limit Exceeded. The last status was: ' . $job->output; // If the Job has been in the queue for more than 1 hour, // move it over to a Error status. if (\Carbon\Carbon::now()->diffInMinutes($job['updated_at']) > 60) { \SeatQueueInformation::where('jobID', '=', $job['jobID'])->update(array('status' => 'Error', 'output' => $new_output)); } } }
public function getDeleteQueuedJob($id) { if (!\Auth::isSuperUser()) { App::abort(404); } // Get the Redis JobID from the databse for this jib $redis_job_id = \SeatQueueInformation::where('id', $id)->pluck('jobID'); // Connect to redis and loop over the queued jobs, looking for the job $redis = new Predis\Client(array('host' => Config::get('database.redis.default.host'), 'port' => Config::get('database.redis.default.port'))); // Loop over the jobs in redis, looking for the one we want to delete foreach ($redis->lrange('queues:default', 0, -1) as $redis_job) { // Delete it if we match the jobID if (strpos($redis_job, $redis_job_id)) { $redis->lrem('queues:default', 0, $redis_job); } } // Delete if from the database too \SeatQueueInformation::where('status', 'Queued')->where('id', $id)->delete(); return Response::json(); }