【问题标题】:Laravel database queuing jobs attemptsLaravel 数据库排队作业尝试
【发布时间】:2016-09-12 18:08:24
【问题描述】:

我在 Ubuntu 14.04 服务器中使用数据库驱动程序实现了一个 laravel 队列。我执行这段代码

php /path to app/artisan queue:listen --tries=3 --env=local

它说尝试=3。但是当我看到工作表时,我看到有 22 次尝试的工作,这怎么可能?它应该尝试 3 次,然后将其添加到 failed_jobs 表中。

另外,在jobs表中reserved_at是什么意思?

谢谢

顺便说一句,这是一个完美的工作

<?php

namespace App\Jobs;

use App\Jobs\Job;
use App\Notifiers\Im_Notification;
use App\Notifiers\Notification;
use App\Notifiers\Mail_Notification;
use App\Reservation;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class NotifyPlaceReservationStatus extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

/**
 * Create a new job instance.
 *
 * @return void
 */
protected $notification;
protected $reservation;
protected $info_changed;

public function __construct(Notification $notification,Reservation $reservation)
{
    $this->reservation = $reservation;
    $this->notification = $notification;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    $this->notification->notifyPlaceReservationStatus($this->reservation);
}

public function failed()
{
    error_log('Job failed');
}
}

【问题讨论】:

  • 你应该展示自己的工作。问题可能就在那里。
  • 好的,我说。谢谢

标签: php mysql laravel laravel-5 queue


【解决方案1】:

当您在 CLI 中提供尝试次数时,Laravel 工作器将仅对当前在队列中的那些作业(或者如果您愿意,也可以在未执行的作业表中)应用尝试次数限制。为了使作业的每次执行都有一个尝试限制,您应该在您的 Job 类中放置一个公共 $tries 属性,如 Dispatching Jobs 上的 Laravel 文档中所述(对于 Laravel 5.4)

public $tries = 3;
protected $notification;
protected $reservation;
protected $info_changed;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-11
    • 2015-11-03
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 2017-06-28
    • 2018-03-24
    相关资源
    最近更新 更多