Exemple #1
0
 /**
  * Adds a Job to the queue only if one does not
  * already exist.
  *
  * @param $job
  * @param $args
  *
  * @return mixed
  */
 public function addUniqueJob($job, JobPayloadContainer $args)
 {
     // Refuse to pop a job onto the queue if the admin
     // has not yet configured an administrative contact.
     // See: https://github.com/eveseat/seat/issues/77 (Request by CCP)
     if ($this->hasDefaultAdminContact()) {
         logger()->error('Default admin contact still set. Not queuing job for: ' . $args->api);
         return 'Failed to queue due to default config';
     }
     // Look for an existing job
     $job_id = JobTracking::where('owner_id', $args->owner_id)->where('api', $args->api)->whereIn('status', ['Queued', 'Working'])->value('job_id');
     // Just return if the job already exists
     if ($job_id) {
         logger()->warning('A job for Api ' . $args->api . ' and owner ' . $args->owner_id . ' already exists.');
         return $job_id;
     }
     // Add a new job onto the queue...
     $new_job = (new $job($args))->onQueue($args->queue);
     $job_id = dispatch($new_job);
     // Check that the id we got back is a random
     // string and not 0. In fact, normal job_ids
     // are like a 32char string, so just check that
     // its more than 2. If its not, we can assume
     // the job itself was not sucesfully added.
     // If it actually is queued, it will get discarded
     // when trackOrDismiss() is called.
     if (strlen($job_id) < 2) {
         return;
     }
     // ...and add tracking information
     JobTracking::create(['job_id' => $job_id, 'owner_id' => $args->owner_id, 'api' => $args->api, 'scope' => $args->scope, 'status' => 'Queued']);
     return $job_id;
 }
Exemple #2
0
 /**
  * Adds a Job to the queue only if one does not
  * already exist.
  *
  * @param $job
  * @param $args
  *
  * @return mixed
  */
 public function addUniqueJob($job, JobContainer $args)
 {
     // Look for an existing job
     $job_id = JobTracking::where('owner_id', $args->owner_id)->where('api', $args->api)->whereIn('status', ['Queued', 'Working'])->value('job_id');
     // Just return if the job already exists
     if ($job_id) {
         return $job_id;
     }
     // Add a new job onto the queue...
     $new_job = (new $job($args))->onQueue($args->queue);
     $job_id = $this->dispatch($new_job);
     // Check that the id we got back is a random
     // string and not 0. In fact, normal job_ids
     // are like a 32char string, so just check that
     // its more than 2. If its not, we can assume
     // the job itself was not sucesfully added.
     // If it actually is queued, it will get discarded
     // when trackOrDismiss() is called.
     if (strlen($job_id) < 2) {
         return;
     }
     // ...and add tracking information
     JobTracking::create(['job_id' => $job_id, 'owner_id' => $args->owner_id, 'api' => $args->api, 'scope' => $args->scope, 'status' => 'Queued']);
     return $job_id;
 }
Exemple #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Determine the timestamp that we will be
     // comparing job age with. Jobs older than this
     // time will be considered expired.
     $oldest_jobs = Carbon::now()->subHour($this->option('hours'))->toDateTimeString();
     $this->info('Cleaning up job older than ' . $this->option('hours') . ' hours. Jobs submitted after ' . $oldest_jobs . ' will be kept.');
     // Clear the jobs older than the determined date that is
     // either Queued and or Working
     JobTracking::whereIn('status', ['Working', 'Queued'])->where('created_at', '<=', $oldest_jobs)->delete();
     $this->info('Cleaning up the failed_jobs table');
     // Truncate the failed_jobs table
     FailedJob::truncate();
     // Analytics
     dispatch((new Analytics((new AnalyticsContainer())->set('type', 'event')->set('ec', 'admin')->set('ea', 'expired_jobs_clear')->set('el', 'console')->set('ev', $this->option('hours'))))->onQueue('medium'));
 }
Exemple #4
0
 /**
  * Write diagnostic information to the Job Tracker
  *
  * @param \Seat\Eveapi\Models\JobTracking $job_tracker
  * @param \Exception                      $e
  */
 public function reportJobError(JobTracking $job_tracker, \Exception $e)
 {
     // Write an entry to the log file.
     Log::error($job_tracker->api . '/' . $job_tracker->scope . ' for ' . $job_tracker->owner_id . ' failed with ' . get_class($e) . ': ' . $e->getMessage() . '. See the job tracker for more ' . 'information.');
     // Prepare some useful information about the error.
     $output = 'Last Updater: ' . $job_tracker->output . PHP_EOL;
     $output .= PHP_EOL;
     $output .= 'Exception: ' . get_class($e) . PHP_EOL;
     $output .= 'Error Code: ' . $e->getCode() . PHP_EOL;
     $output .= 'Error Message: ' . $e->getMessage() . PHP_EOL;
     $output .= 'File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . PHP_EOL;
     $output .= PHP_EOL;
     $output .= 'Traceback: ' . $e->getTraceAsString() . PHP_EOL;
     $job_tracker->status = 'Error';
     $job_tracker->output = $output;
     $job_tracker->save();
     return;
 }
Exemple #5
0
 /**
  * Return a count summary of the jobs in
  * the queue
  *
  * @return array
  */
 public function count_summary()
 {
     $response = ['total_jobs' => JobTracking::count('job_id'), 'working_jobs' => JobTracking::where('status', 'Working')->count('job_id'), 'queued_jobs' => JobTracking::where('status', 'Queued')->count('job_id'), 'done_jobs' => JobTracking::where('status', 'Done')->count('job_id'), 'error_jobs' => JobTracking::where('status', 'Error')->count('job_id')];
     return $response;
 }
Exemple #6
0
 /**
  * @param $api_key
  *
  * @return \Illuminate\View\View
  */
 public function getDetail($api_key)
 {
     $key = ApiKeyModel::with('info', 'characters', 'status')->where('key_id', $api_key)->firstOrFail();
     $access_map = null;
     if ($key->info) {
         $access_map = $key->info->type == 'Corporation' ? config('eveapi.access_bits.corp') : config('eveapi.access_bits.char');
     }
     $jobs = JobTracking::where('owner_id', $api_key)->orderBy('created_at', 'desc')->take(50)->get();
     // Get worker information.
     $key_type = $key->info->type == 'Corporation' ? 'corporation' : 'character';
     $available_workers = config('eveapi.worker_groups');
     $current_workers = $key->api_call_constraints;
     return view('web::api.detail', compact('key', 'access_map', 'jobs', 'key_type', 'available_workers', 'current_workers'));
 }
 /**
  * @return mixed
  */
 public function clearErroredJobHistory()
 {
     return JobTracking::where('status', 'Error')->delete();
 }
Exemple #8
0
 /**
  * @param $api_key
  *
  * @return \Illuminate\View\View
  */
 public function getDetail($api_key)
 {
     $key = ApiKeyModel::with('info', 'characters')->where('key_id', $api_key)->firstOrFail();
     $access_map = null;
     if ($key->info) {
         $access_map = $key->info->type == 'Corporation' ? config('eveapi.access_bits.corp') : config('eveapi.access_bits.char');
     }
     $jobs = JobTracking::where('owner_id', $api_key)->orderBy('created_at', 'desc')->get();
     return view('web::api.detail', compact('key', 'access_map', 'jobs'));
 }
Exemple #9
0
 /**
  * Update the JobTracker with a new status.
  *
  * @param array $data
  */
 public function updateJobStatus(array $data)
 {
     $this->job_tracker->fill($data);
     $this->job_tracker->save();
     return;
 }
Exemple #10
0
 /**
  * Clear the database job tracking cache
  */
 public function clear_database_jobs()
 {
     $this->info('Clearing the database Job Tracking Cache');
     JobTracking::truncate();
 }