Laravel多名工人两次工作 [英] Laravel multiple workers running job twice

查看:71
本文介绍了Laravel多名工人两次工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.6,并且正在将作业分派到一个队列,然后使用主管激活该队列上的8个工作程序.我原以为Laravel不会两次执行相同的工作,但令我惊讶的是它确实做到了. 这项工作由多名工人负责,因此奇怪的事情开始发生.

I am using Laravel 5.6 and I am dispatching jobs to a queue and then using supervisor to activate 8 workers on that queue. I was expecting that Laravel will know NOT to run the same job twice but I was surprised to discover that it did. Same job was taken cared of by more than one worker and therefore weird stuff started to happen.

问题是,一年前,我为另一个Laravel项目(但在Laravel 5.1版上)编写了相同的机制,并且整个过程都可以立即使用.我不必进行任何配置.

The thing is that one year ago I wrote the same mechanism for another Laravel project (but on Laravel version 5.1) and the whole thing worked out of the box. I didn't have to configure anything.

任何人都可以帮忙吗? 谢谢.

Anyone can help? Thank you.

推荐答案

我遇到了完全相同的问题,这让我发疯,直到我设法解决它!

I was having the exact same problem and It drove me crazy until I managed to solve it!

出于某种原因,Laravel 5.6使用engine = MyISAM创建了"jobs"表,该表不支持事务,而事务对于锁定机制是必需的,这种锁定机制可以防止作业运行两次.我相信在Laravel 5.1中会有所不同,因为我也曾经使用Laravel 5.4编写过一个应用程序,并且可以与8位工作人员完美协作.当我使用Laravel 5.6做同样的事情时,它不起作用.与您描述的相同.

For some reason Laravel 5.6 creates the "jobs" table with engine=MyISAM which does not support transactions which are necessary for the locking mechanism that prevents the case of job runs twice. I believe that it was different in Laravel 5.1 because I also once wrote an app with Laravel 5.4 and it worked perfectly with 8 workers. When I did the same thing with Laravel 5.6 it didn't work. Same as you describe.

一旦我将引擎更改为支持事务的InnoDB,一切都会按预期工作,并且锁定机制开始起作用.

Once I've changed the Engine to InnoDB which supports transactions everything worked as expected and the locking mechanism started to work.

所以基本上您需要做的是:

So basically all you need to do is:

ALTER TABLE jobs ENGINE = InnoDB;

希望能解决您的痛苦...

Hope that will solve your misery...

这篇关于Laravel多名工人两次工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆