简体   繁体   English

如何暂停 Laravel Horizon 中的主管

[英]How to pause a supervisor in Laravel Horizon

I have multiple supervisor in horizon, and they work normally, the problem is that I want to interact with them by my own web interface, and by interacting I mean pause them and continue (unpause them).我在地平线上有多个主管,他们工作正常,问题是我想通过我自己的 web 接口与他们进行交互,并且通过交互我的意思是pause他们并continue (取消暂停他们)。

To do that I want to be able as much as possible, without using system (in artisan horizon:pause-supervisor it sends posix_kill($supervisor->pid, 12)) .为此,我希望尽可能不使用系统(在artisan horizon:pause-supervisor中它发送posix_kill($supervisor->pid, 12))

I tried to instantiate the supervisor by doing this:我试图通过这样做来实例化主管:

class HorizonManager
{
    private SupervisorRepository       $supervisors;
    private MasterSupervisorRepository $masters;
    private WorkloadRepository         $workload;
    private RedisJobRepository         $jobRepository;
    private QueueManager               $queueManager;

    public function __construct(MasterSupervisorRepository $masters, SupervisorRepository $supervisors, WorkloadRepository $workload, RedisJobRepository $jobRepository, QueueManager $manager)
    {
        $this->masters = $masters;
        $this->supervisors = $supervisors;
        $this->workload = $workload;
        $this->jobRepository = $jobRepository;
        $this->queueManager = $manager;

    }

    public function pauseSupervisor(string $supervisorName){
        $supervisor = $this->supervisors->find($supervisorName);
        $supervisorOpt = new SupervisorOptions(...$supervisor->options);
        $sup = new Supervisor($supervisorOpt);
        $sup->pause();
        $sup->persist();
        return $this->supervisors->find($supervisorName);
    }
}

In the return from the function, I have the supervisor paused, but it's not really paused (even If I persist the instantiate supervisor it's still running as a process)在 function 的返回中,我暂停了主管,但它并没有真正暂停(即使我坚持实例化主管它仍然作为一个进程运行)

For those interested I failed doing it by instanciating it so instead I send the command using artisan call:对于那些感兴趣的人,我通过实例化它失败了,所以我改为使用 artisan 调用发送命令:

define('SIGUSR2', 12);
Artisan::call('horizon:pause-supervisor', ['name'=>$supervisorName]);
$supervisor = $this->supervisors->find($supervisorName);
$supervisor->status = 'paused';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM