为了处理大量的作业(job),我根据需要完成的工作量运行不同数量的队列工作人员.我不想让更多的工人在我们认为合适的时间内完成需要完成的工作.

At the moment, I start 5 daemon queue workers for testing purposes, however in production this number could be between 25 & 100 workers, possibly more. I understand that when deploying, I have to stop the queue workers by first placing the framework in maintenance mode by using php artisan down, because the --daemon flag causes the framework to only load when the worker starts up, hence new code would not take affect during the deploy until the worker restarts.

如果我出于某种原因需要停止工人,我可以使用php artisan down将应用程序置于维护模式,这将导致工人在处理完当前工作后死亡(如果他们正在工作的话).然而,有时我可能想在不将整个应用程序置于维护模式的情况下杀死工人.

Is there a safe way to stop the workers in a way where they will continue processing their current job and then die without placing the whole application in maintenance mode?

Essentially what I need is a 100, which behaves like 101, but does not restart the worker once the job is done.

我曾希望有一个类似于php artisan queue:stop的命令可以做到这一点,但事实似乎并非如此.

使用ps aux | grep php,我能够获得进程ID的工人,我可以杀死进程的方式,但我不想杀死过程中的中间工作的一项工作.

Thanks.

推荐答案

我们在我们的应用程序中实现了类似的东西-但这不是Laravel本身内置的东西.您必须通过向if-挡路添加另一个条件来编辑this file,这样它才能调用第stop函数.您可以通过在第Worker类中设置一个静电变量(每当您运行您必须执行的自定义命令时都会更改该变量),或者通过判断某个地方的原子值(即,将其设置在一些缓存中,如redis、memcached、apc甚至mysql,尽管这意味着您使用相同的自定义命令设置的WHILE循环的每个周期都有一个mysql查询)来实现这一点.

Laravel相关问答推荐

Livewire 3分页在点击后不更新页面

如何在Vite和Rollup中完全禁用分块?

LARAVEL 从多个表中获取重复的行

Laravel Livewire 组件属性在 div 类中为空

如何更改 laravel sanctum 返回message: Unauthenticated.

"public/index.php" 可以在 laravel 中按组写入

Laravel & Docker:无法打开流或文件/var/www/html/storage/logs/laravel.log:无法打开流:权限被拒绝

调用未定义函数 Illuminate\Encryption\openssl_decrypt()

验证规则 required_if 与其他条件(Laravel 5.4)

Laravel 判断约束违规

Eloquent 的 Model::query() 是什么意思?

laravel 4 - 如何限制(采取和跳过)Eloquent的 ORM?

为什么在 Laravel 的 DB::select 中使用 DB::raw?

WhereHas Laravel 中的关系计数条件是什么

在 Laravel 5 控制器中找不到类App\Http\Controllers\DB

Laravel:array_merge():参数#2不是数组错误

无法在控制器的构造函数上调用 Auth::user()

如何让 Laravel 将 View 的Content-Type标头返回为application/javascript?

如何使用 Laravel 迁移在 Mysql 列中添加注释

将参数传递给过滤器 - Laravel 4