Пример #1
0
$app = new \Slim\App();
$container = $app->getContainer();
$pheanstalk = new \Pheanstalk\Pheanstalk($config['beanstalk_server']);
$view = new \Slim\Views\Twig('templates');
$view->addExtension(new Slim\Views\TwigExtension($container->get('router'), $container->get('request')->getUri()));
$container->register($view);
$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];