我在地平线上有多个主管,他们正常工作,问题是我想通过我自己的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);
}
}
在从函数返回,我有监督暂停,但它不是真正暂停(即使我坚持实例化的监督,它仍然作为一个进程运行)
对于那些感兴趣的人,我没有通过实例化它来完成它,所以我使用artisan call发送命令:
define('SIGUSR2', 12);
Artisan::call('horizon:pause-supervisor', ['name'=>$supervisorName]);
$supervisor = $this->supervisors->find($supervisorName);
$supervisor->status = 'paused';