/** * 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; }
/** * 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; }