php 如何暂停Laravel Horizon中的主管

f8rj6qna  于 2023-01-01  发布在  PHP
关注(0)|答案(1)|浏览(159)

我在Horizon中有多个管理员,他们工作正常,问题是我想通过自己的Web界面与他们交互,而交互是指pause他们和continue(取消暂停他们)。
要做到这一点,我希望能够尽可能多地,而不使用系统(在artisan horizon:pause-supervisor中,它发送posix_kill($supervisor->pid, 12))
我试着通过以下方式示例化管理器:

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);
    }
}

在函数的返回中,我暂停了管理程序,但它并没有真正暂停(即使我持久化了示例化的管理程序,它仍然作为一个进程运行)

bfnvny8b

bfnvny8b1#

对于那些感兴趣的人,我没有通过示例化它来完成它,所以我使用工匠调用发送命令:

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

相关问题