本文整理汇总了PHP中Illuminate\Queue\Jobs\Job::attempts方法的典型用法代码示例。如果您正苦于以下问题:PHP Job::attempts方法的具体用法?PHP Job::attempts怎么用?PHP Job::attempts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Queue\Jobs\Job
的用法示例。
在下文中一共展示了Job::attempts方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* @param Job $job
* @param array $data
*/
public function fire(Job $job, $data)
{
$signalId = $data['signalId'];
$signalResult = ResultSignal::find($signalId);
if ($signalResult == null) {
$job->delete();
exit;
}
$url = $data['url'];
$signalSid = $signalResult->signal_sid;
$isSend = $this->makeCurl($url, $signalSid);
//Если отправлен результат то удаляем задачу и ставим флаг
if ($isSend) {
$job->delete();
$signalResult->setFlagUrlTrue();
Log::info('Результат отправлен по http.');
}
$cnt = $job->attempts();
if ($cnt > 50) {
$job->delete();
Log::info('Выполнено ' . $cnt . ' попыток отправить curl. Задача удалена.', $data);
exit;
}
Log::info('Перевыставлена задача, попытка номер ' . $cnt, $data);
$job->release(60);
}
示例2: fire
public function fire(Job $job, $data)
{
// Stop if over three attempts
if ($job->attempts() > 3) {
Log::info("Job Delete: " . serialize($job));
$job->delete();
}
// Begin
try {
$image = Image::find($data['image_id']);
$corners = $image->getBoundingBox();
$rgba = Litmus::getAverageColor($image->url, $corners[0], $corners[1], $corners[2], $corners[3]);
//Update Image
$image->red = $rgba->red;
$image->green = $rgba->green;
$image->blue = $rgba->blue;
$image->alpha = $rgba->alpha;
$image->status = "done";
$image->save();
Event::fire('image.done', [$image]);
} catch (\Exception $e) {
Log::error($e->getMessage());
$job->release();
}
// Success, delete job...
$job->delete();
}
示例3: fire
public function fire(Job $job, $data)
{
$doSuccess = false;
// push to url
if ($data['url']) {
$curl = new Curl();
$curl->post($data['url'], $data['data']);
$doSuccess = $curl->ok();
if (!$doSuccess) {
Log::warning('callback.push.url', array('message' => 'callback push failed to ' . $data['url'], 'order' => $data['data']['order']));
}
}
// push to email
if ($data['email']) {
Mail::send(array('text' => 'ff-bank-em::demo.email_callback'), $data, function (Message $message) use($data) {
$message->to($data['email'])->subject('Bank Emulator Payment Message');
});
$doSuccess = 0 == count(Mail::failures());
if (!$doSuccess) {
Log::warning('callback.push.email', array('message' => 'callback push failed', 'order' => $data['data']['order']));
}
}
// release, if error
if ($doSuccess) {
Log::info('callback.push', array('order' => $data['data']['order']));
$job->delete();
} else {
Log::warning('callback.push', array('order' => $data['data']['order']));
if ($job->attempts() > 10) {
$job->delete();
} else {
$job->release(60);
}
}
}
示例4: fire
/**
* @param Job $job
* @param array $data
*/
public function fire(Job $job, array $data)
{
if (empty($data['url'])) {
$job->delete();
Log::info('Не указан url для отправки callback.');
return;
}
$ch = curl_init($data['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $data['merchant_id'] . ':' . $data['merchant_pass']);
if ($data['sign'] != '') {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Api-Signature:' . $data['sign']));
}
unset($data['url'], $data['merchant_id'], $data['merchant_pass'], $data['sign']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$httpError = curl_error($ch);
Log::info('Ошибки curl:', array('httpError' => $httpError));
if (!empty($result) && strpos($result, '<result_code>0</result_code>') !== false) {
Log::info('Успешно вызван callback с ответом 0', array('result' => $result));
$job->delete();
return;
}
Log::info('Результат curl:', array('result' => $result));
$cnt = $job->attempts();
if ($cnt > 50) {
$job->delete();
return;
}
Log::info('Перевыставлена задача по отправке curl, попытка номер ' . $cnt, $data);
$job->release(60 * $cnt);
}
示例5: fire
/**
* @param Job $job
* @param array $data
*/
public function fire(Job $job, array $data)
{
if (empty($data['email'])) {
$job->delete();
Log::info('Не указан url для отправки callback.');
return;
}
switch ($data['status']) {
case Bill::C_STATUS_EXPIRED:
$data['textStatus'] = ' просрочен.';
break;
case Bill::C_STATUS_PAID:
$data['textStatus'] = ' оплачен.';
break;
case Bill::C_STATUS_REJECTED:
$data['textStatus'] = ' отменён.';
break;
default:
$data['textStatus'] = null;
}
$this->email = $data['email'];
$this->billId = $data['bill_id'];
$this->textStatus = $data['textStatus'];
Mail::send('ff-qiwi-gate::emails.sendCallbackMail', $data, function (Message $message) {
$message->to($this->email)->subject('Счёт №' . $this->billId . $this->textStatus);
});
$cntSendFails = count(Mail::failures());
if ($cntSendFails == 0) {
$job->delete();
Log::info('Почта отправлена.', $data);
return;
}
$cnt = $job->attempts();
if ($cnt > 50) {
$job->delete();
return;
}
Log::info('Перевыставлена задача по отправке почты, попытка номер ' . $cnt, $data);
$job->release(60 * $cnt);
}
示例6: process
/**
* Process a given job from the queue.
*
* @param string $connection
* @param \Illuminate\Queue\Jobs\Job $job
* @param int $maxTries
* @param int $delay
* @return void
*
* @throws \Exception
*/
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();
if ($job->autoDelete()) {
$job->delete();
}
} 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;
}
}
示例7: attempts
/**
* Get the number of times the job has been attempted.
*
* @return int
*/
public function attempts()
{
$this->job->attempts();
}