Laravel 队列失败的作业

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26030411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:09:56  来源:igfitidea点击:

Laravel Queue Failed Jobs

phplaravelqueuesupervisordbeanstalkd

提问by Yuusha

I was trying to record some data from other table when the jobs fails. It works great in failed jobs table but I cant get the Queue::failing(function($connection, $job, $data)to work every time the job failed. I did try to put it in global.phpbut no luck.

当作业失败时,我试图从其他表中记录一些数据。它在失败的工作表中效果很好,但Queue::failing(function($connection, $job, $data)每次工作失败时我都无法工作。我确实尝试将其放入global.php但没有运气。

Another question is what does the $jobreturn? An object or just the job id?

另一个问题是$job回报是什么?一个对象还是只是工作 ID?

采纳答案by Yuusha

Work on global php. Its causing an error, just changed following:

工作global php。它导致错误,只是更改了以下内容:

Queue::failing(function($connection, $job, $data)

To:

到:

Queue::failing(function($connection, $job)

回答by Estev?o Lucas

You should call queue:work with --tries param, for ex:

您应该调用 queue:work with --tries 参数,例如:

$ php artisan queue:work sqs --tries=1

Without this params, your job will never get failed.

没有这个参数,你的工作永远不会失败。

But remember to config you failed table.

但请记住配置您失败的表。

1) Create migration file:

1) 创建迁移文件:

$ php artisan queue:failed-table

2) Run migrate to create table

2) 运行 migrate 创建表

$ php artisan migrate

3) In queue.php you need to config you 'failed' table. Ex:

3) 在 queue.php 中,您需要配置“失败”表。前任:

'failed' => array(
    'database' => 'pgsql', 'table' => 'failed_jobs',
),

Now, when the job gets failed, it will insert it into failed_jobstable.

现在,当作业失败时,它会将其插入到failed_jobs表中。

Just run php artisan queue:failedto get the failed list.

只需运行php artisan queue:failed即可获取失败的列表。