public function setup() { $this->runner = \Mockery::mock("Silktide\\Teamster\\Pool\\Runner\\RunnerInterface"); $this->runnerFactory = \Mockery::mock("Silktide\\Teamster\\Pool\\Runner\\RunnerFactory"); $this->runnerFactory->shouldReceive("createRunner")->andReturn($this->runner); $this->pid = \Mockery::mock("Silktide\\Teamster\\Pool\\Pid\\PidInterface")->shouldIgnoreMissing(true); $this->pidFactory = \Mockery::mock("Silktide\\Teamster\\Pool\\Pid\\PidFactoryInterface"); $this->pidFactory->shouldReceive("create")->andReturn($this->pid); $this->inputDefinition = \Mockery::mock("Symfony\\Component\\Console\\Input\\InputDefinition"); $this->input = \Mockery::mock("Symfony\\Component\\Console\\Input\\InputInterface"); $this->output = \Mockery::mock("Symfony\\Component\\Console\\Output\\OutputInterface")->shouldIgnoreMissing(); vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($this->testDir)); }
public function setup() { $this->runner = \Mockery::mock("Silktide\\Teamster\\Pool\\Runner\\RunnerInterface")->shouldIgnoreMissing(); $this->runner->shouldReceive("isRunning")->andReturn(true); $this->completedRunner = \Mockery::mock("Silktide\\Teamster\\Pool\\Runner\\RunnerInterface")->shouldIgnoreMissing(); $this->completedRunner->shouldReceive("isRunning")->andReturn(false); $this->runnerFactory = \Mockery::mock("Silktide\\Teamster\\Pool\\Runner\\RunnerFactory"); $this->runnerFactory->shouldReceive("createRunner")->withArgs(["console", "/^(?!completed-).*/", \Mockery::type("int")])->andReturn($this->runner); $this->runnerFactory->shouldReceive("createRunner")->withArgs(["console", "/^completed-/", \Mockery::type("int")])->andReturn($this->completedRunner); $this->pid = \Mockery::mock("Silktide\\Teamster\\Pool\\Pid\\PidInterface")->shouldIgnoreMissing(true); $this->pidFactory = \Mockery::mock("Silktide\\Teamster\\Pool\\Pid\\PidFactoryInterface"); $this->pidFactory->shouldReceive("create")->andReturn($this->pid); $this->inputDefinition = \Mockery::mock("Symfony\\Component\\Console\\Input\\InputDefinition"); $this->input = \Mockery::mock("Symfony\\Component\\Console\\Input\\InputInterface"); $this->output = \Mockery::mock("Symfony\\Component\\Console\\Output\\OutputInterface")->shouldIgnoreMissing(); }
/** * gets the PID number from the PID file and caches it * * @param bool $skipCache * @return int */ protected function getPid($skipCache = false) { $skipCache = (bool) $skipCache; if (!$skipCache && !empty($this->pid) && $this->pid instanceof Pid) { return $this->pid->getPid(); } $pid = $this->pidFactory->create($this->poolPidFile); $pidNum = $pid->getPid(); $this->pid = $pid; return $pidNum; }
/** * stop all the runners and remove the pool's PID file */ public function __destruct() { foreach ($this->pool as $service => $pool) { foreach ($pool as $i => $instance) { /** @var RunnerInterface $runner */ $runner = $instance["runner"]; $pid = $this->pidFactory->create($instance["pidFile"]); $this->output->writeln("<comment>Finishing runner {$i} of {$service}</comment>"); $runner->finish($pid); } } if (count($this->pool) > 0) { $pid = $this->pidFactory->create($this->poolPidFile); $pid->cleanPid(); } }
/** * @param PidInterface|string $pid * @return bool */ public function isRunning($pid = "") { if (is_resource($this->process)) { // check if the process is still running $status = proc_get_status($this->process); if (!$status["running"] && ($pid instanceof PidInterface || is_string($pid) && !empty($pid))) { if (!$pid instanceof PidInterface) { $pid = $this->pidFactory->create($pid); } // clean PID file if we didn't exit cleanly $pid->cleanPid(); } return $status["running"]; } return false; }