如何切换拉拉维尔队列是否运行



我刚刚创建了自己的维护模式,称为应用程序维护模式扩展检查维护模式。

class ApplicationMaintenanceMode extends CheckForMaintenanceMode
{
....
}

并且还扩展了应用程序类

use IlluminateFoundationApplication as App;
class Application extends App
{
....
....
public function isApplicationDownForMaintenance()
{
//code
}
}

然后,我也像原来一样创建了自己的DownCommand。

class DownCommand extends Command
{    
protected $signature = 'app_down {--message= : The message for the maintenance mode. }
{--retry= : The number of seconds after which the request may be retried.}
{--only=* : Routes to be include from maintenance mode.}
{--type=* : Type of maintenance mode.}
{--except=* : Routes to be exclude from maintenance mode.}
{--version_allow= : Application Version allowed.}
{--lock_queue=false : Application Queue need to run or not.}
{--allow=* : IP or networks allowed to access the application while in maintenance mode.}';
}

如您所见 --lock_queue 我想切换队列工作线程的位置可以运行,也可以不运行。目的是在原来的维护模式下,它停止所有队列。我想要实现的是我希望队列在维护模式下可以轻松切换为运行或不运行的位置。

有什么办法可以做到吗? 我应该覆盖 QueueManager 和 Worker 类吗?

您需要在队列工作者中添加--force标志以强制队列在维护模式下运行,例如。

php artisan queue:work --force

您需要停止所有队列工作线程,然后根据需要添加此标志。

请参阅:https://divinglaravel.com/queue-workers-how-they-work

最新更新