本文整理匯總了PHP中Illuminate\Contracts\Queue\Job::attempts方法的典型用法代碼示例。如果您正苦於以下問題:PHP Job::attempts方法的具體用法?PHP Job::attempts怎麽用?PHP Job::attempts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Contracts\Queue\Job
的用法示例。
在下文中一共展示了Job::attempts方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fire
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();
}
示例2: fire
public function fire(Job $job, $data)
{
if ($job->attempts() > 2) {
$job->delete();
}
$this->factory->getProject($data['project'])->githubSync()->syncAll();
}
示例3: process
/**
* 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;
}
}
示例4: process
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;
}
}
示例5: markJobAsFailedIfHasExceededMaxAttempts
/**
* 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);
}
示例6: process
/**
* 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);
}
}
示例7: attempts
/**
* Get the number of times the job has been attempted.
*
* @return int
*/
public function attempts()
{
return $this->job ? $this->job->attempts() : 1;
}
示例8: markJobAsFailedIfHasExceededMaxAttempts
/**
* 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);
}
示例9: process
/**
* 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);
}
}