private function _createPheanstalk() { $pheanstalk = new \Pheanstalk\Pheanstalk(self::SERVER_HOST); $tube = preg_replace('#[^a-z]#', '', strtolower(__CLASS__)); $pheanstalk->useTube($tube)->watch($tube)->ignore('default'); try { while ($pheanstalk->delete($pheanstalk->peekDelayed())) { } } catch (\Pheanstalk\Exception\ServerException $e) { } try { while ($pheanstalk->delete($pheanstalk->peekReady())) { } } catch (\Pheanstalk\Exception\ServerException $e) { } return $pheanstalk; }
$app->get('/', function ($req, $res) { return $this->view->render($res, 'index.html', ['currentTube' => 'default']); }); $app->get('/api/info', function ($req, $res) use($pheanstalk, $config) { $tube = $req->getParam('tube', 'default'); try { $isServiceListening = $pheanstalk->getConnection()->isServiceListening(); try { $job = $pheanstalk->peekBuried($tube); $statsJob = $pheanstalk->statsJob($job); $jobBuried = ['data' => $job->getData(), 'stats' => $statsJob]; } catch (\Pheanstalk\Exception\ServerException $e) { $jobBuried = null; } try { $job = $pheanstalk->peekDelayed($tube); $statsJob = $pheanstalk->statsJob($job); $jobDelayed = ['data' => $job->getData(), 'stats' => $statsJob]; } catch (\Pheanstalk\Exception\ServerException $e) { $jobDelayed = null; } try { $job = $pheanstalk->peekReady($tube); $statsJob = $pheanstalk->statsJob($job); $jobReady = ['data' => $job->getData(), 'stats' => $statsJob]; } catch (\Pheanstalk\Exception\ServerException $e) { $jobReady = null; } $statsTube = $pheanstalk->statsTube($tube)->getArrayCopy(); $stats = $pheanstalk->stats()->getArrayCopy(); $tubes = $pheanstalk->listTubes();