public function fire(Job $job, $data) { $this->codex->log('alert', 'codex.hooks.git.sync.project.command', ['jobName' => $job->getName(), 'jobAttempts' => $job->attempts(), 'project' => $data['project']]); if ($job->attempts() > 2) { $job->delete(); } $this->codex->getProject($data['project'])->gitSyncer()->syncAll(); }
public function fire(Job $job, $data) { if ($job->attempts() > 2) { $job->delete(); } $this->factory->getProject($data['project'])->githubSync()->syncAll(); }
/** * Process a given job from the queue. * * @param string $connection * @param \Illuminate\Contracts\Queue\Job $job * @param int $maxTries * @param int $delay * @return array|null * * @throws \Throwable */ public function process($connection, Job $job, $maxTries = 0, $delay = 0) { // @TODO Tests using File::put('/test', serialize()); if ($maxTries > 0 && $job->attempts() > $maxTries) { return $this->logFailedJob($connection, $job); } try { // First we will fire off the job. Once it is done we will see if it will // be auto-deleted after processing and if so we will go ahead and run // the delete method on the job. Otherwise we will just keep moving. $this->setJob($job); if ($this->isAnSqsJob()) { $job = $this->processSqsJob($job); } $job->fire(); $this->raiseAfterJobEvent($connection, $job); return ['job' => $job, 'failed' => false]; } catch (Exception $e) { // If we catch an exception, we will attempt to release the job back onto // the queue so it is not lost. This will let is be retried at a later // time by another listener (or the same one). We will do that here. if (!$job->isDeleted()) { $job->release($delay); } throw $e; } catch (Throwable $e) { if (!$job->isDeleted()) { $job->release($delay); } throw $e; } }
public function process($connection, Job $job, $maxTries = 0, $delay = 0) { if ($maxTries > 0 && $job->attempts() > $maxTries) { return $this->logFailedJob($connection, $job); } try { // First we will fire off the job. Once it is done we will see if it will // be auto-deleted after processing and if so we will go ahead and run // the delete method on the job. Otherwise we will just keep moving. $job->fire(); return ['job' => $job, 'failed' => false]; } catch (Exception $e) { // If we catch an exception, we will attempt to release the job back onto // the queue so it is not lost. This will let is be retried at a later // time by another listener (or the same one). We will do that here. if (!$job->isDeleted()) { // Add exponential delay based on the job attempts and the provided delay seconds. // The delay will default to 30 seconds by default or when delay is set to zero. // A max delay of 2 hours will be used when exponential delay exceeds 2 hours // Example of delay in seconds: 30, 60, 90, 180, ... 7200 $delay = $delay ?: 30; $delay = $job->attempts() > 1 ? pow(2, $job->attempts() - 2) * $delay : 0; $maxDelay = 60 * 60 * 2; if ($delay > $maxDelay) { $delay = $maxDelay; } $job->release($delay); } throw $e; } }
/** * Mark the given job as failed if it has exceeded the maximum allowed attempts. * * @param string $connectionName * @param \Illuminate\Contracts\Queue\Job $job * @param int $maxTries * @param \Exception $e * @return void */ protected function markJobAsFailedIfHasExceededMaxAttempts($connectionName, $job, $maxTries, $e) { $maxTries = !is_null($job->maxTries()) ? $job->maxTries() : $maxTries; if ($maxTries === 0 || $job->attempts() < $maxTries) { return; } $this->failJob($connectionName, $job, $e); }
/** * Process a given job from the queue. * * @param string $connection * @param \Illuminate\Contracts\Queue\Job $job * @param int $maxTries * @param int $delay * @return array|null * * @throws \Throwable */ public function process($connection, Job $job, $maxTries = 0, $delay = 0) { if ($maxTries > 0 && $job->attempts() > $maxTries) { return $this->logFailedJob($connection, $job); } try { $this->raiseBeforeJobEvent($connection, $job); // First we will fire off the job. Once it is done we will see if it will be // automatically deleted after processing and if so we'll fire the delete // method on the job. Otherwise, we will just keep on running our jobs. $job->fire(); $this->raiseAfterJobEvent($connection, $job); return ['job' => $job, 'failed' => false]; } catch (Exception $e) { $this->handleJobException($connection, $job, $delay, $e); } catch (Throwable $e) { $this->handleJobException($connection, $job, $delay, $e); } }
/** * Get the number of times the job has been attempted. * * @return int */ public function attempts() { return $this->job ? $this->job->attempts() : 1; }
/** * Mark the given job as failed if it has exceeded the maximum allowed attempts. * * @param string $connectionName * @param \Illuminate\Contracts\Queue\Job $job * @param int $maxTries * @param \Exception $e * @return void */ protected function markJobAsFailedIfHasExceededMaxAttempts($connectionName, $job, $maxTries, $e) { if ($maxTries === 0 || $job->attempts() < $maxTries) { return; } // If the job has failed, we will delete it, call the "failed" method and then call // an event indicating the job has failed so it can be logged if needed. This is // to allow every developer to better keep monitor of their failed queue jobs. $job->delete(); $job->failed($e); $this->raiseFailedJobEvent($connectionName, $job, $e); }
/** * Process a given job from the queue. * * @param string $connection * @param \Illuminate\Contracts\Queue\Job $job * @param int $maxTries * @param int $delay * @return void * * @throws \Throwable */ public function process($connection, Job $job, $maxTries = 0, $delay = 0) { if ($maxTries > 0 && $job->attempts() > $maxTries) { return $this->logFailedJob($connection, $job); } try { $this->raiseBeforeJobEvent($connection, $job); // Here we will fire off the job and let it process. We will catch any exceptions so // they can be reported to the developers logs, etc. Once the job is finished the // proper events will be fired to let any listeners know this job has finished. $job->fire(); $this->raiseAfterJobEvent($connection, $job); } catch (Exception $e) { $this->handleJobException($connection, $job, $delay, $e); } catch (Throwable $e) { $this->handleJobException($connection, $job, $delay, $e); } }