Exemplo n.º 1
0
function getBeanstalk()
{
    $beanstalk = new Pheanstalk\Pheanstalk(configParam('beanstalk_host'));
    if (configParam('beanstalk_tube') == 'default') {
        $beanstalk->watch(configParam('beanstalk_tube'));
    } else {
        $beanstalk->watch(configParam('beanstalk_tube'))->ignore('default');
    }
    return $beanstalk;
}
Exemplo n.º 2
0
 function index()
 {
     $beanstalk = new \Pheanstalk\Pheanstalk('127.0.0.1');
     $beanstalk->useTube("testtube");
     /*for($i=1;$i<=100;$i++) {
           $id = $beanstalk->putInTube("testtube","job payload goes heres\n".$i);
           echo $id.PHP_EOL;
       }*/
     $job = $beanstalk->watch("testtube")->ignore('default')->reserve();
     echo $job->getData();
     //$beanstalk->delete($job);
 }
Exemplo n.º 3
0
 public function testConnectionResetIfSocketExceptionIsThrown()
 {
     $pheanstalk = new \Pheanstalk\Pheanstalk(self::SERVER_HOST, self::SERVER_PORT, self::CONNECT_TIMEOUT);
     Mock::generate('Pheanstalk\\Connection', 'MockPheanstalk_Connection');
     $connection = new MockPheanstalk_Connection('');
     $connection->returns('getHost', self::SERVER_HOST);
     $connection->returns('getPort', self::SERVER_PORT);
     $connection->returns('getConnectTimeout', self::CONNECT_TIMEOUT);
     $connection->throwOn('dispatchCommand', new \Pheanstalk\Exception\SocketException('socket error simulated'));
     $pheanstalk->putInTube('testconnectionreset', __METHOD__);
     $pheanstalk->watchOnly('testconnectionreset');
     $pheanstalk->setConnection($connection);
     $connection->expectOnce('dispatchCommand');
     $job = $pheanstalk->reserve();
     $this->assertEqual(__METHOD__, $job->getData());
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
<?php

require 'vendor/autoload.php';
require 'config.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\NestedValidationExceptionInterface;
$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) {
Exemplo n.º 6
0
<?php

use PMG\Queue;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/StreamLogger.php';
$conn = new \Pheanstalk\Pheanstalk('localhost');
$tubes = $conn->listTubes();
do {
    $queueName = uniqid('example_');
} while (in_array($queueName, $tubes, true));
$serializer = new Queue\Serializer\SigningSerializer(new Queue\Serializer\NativeSerializer(), "sshhhh, it's a secret");
$driver = new Queue\Driver\PheanstalkDriver($conn, [], $serializer);
$router = new Queue\Router\MappingRouter(['TestMessage' => $queueName, 'TestMessage2' => $queueName, 'MustStop' => $queueName]);
$resolver = new Queue\Resolver\MappingResolver(['TestMessage' => function () {
    // noop
}, 'TestMessage2' => function () {
    throw new \Exception('oops');
}, 'MustStop' => function () {
    throw new Queue\Exception\SimpleMustStop('stopit');
}]);
$producer = new Queue\DefaultProducer($driver, $router);
$consumer = new Queue\DefaultConsumer($driver, new Queue\Executor\SimpleExecutor($resolver), new Queue\Retry\NeverSpec(), new StreamLogger());
$producer->send(new Queue\SimpleMessage('TestMessage'));
$producer->send(new Queue\SimpleMessage('TestMessage2'));
$producer->send(new Queue\SimpleMessage('MustStop'));
exit($consumer->run($queueName));
Exemplo n.º 7
0
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
error_reporting(error_reporting() & ~E_USER_DEPRECATED);
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/../app/config/parameters.yml"));
$app->get('/', function () use($app) {
    return $app->redirect('https://www.devboard.xyz/');
});
$app->post('/github/', function (Request $request) use($app) {
    $webHookSecret = $app['parameters']['github_webhook_secret'];
    $beanstalkIp = $app['parameters']['beanstalk'];
    $eventFactory = new \DevBoard\Notify\EventFactory();
    $securityChecker = new \DevBoard\Notify\EventSecurityChecker($webHookSecret);
    $event = $eventFactory->create($request);
    if (!$securityChecker->check($event)) {
        return new Response('Wrong sig!', 400);
    }
    $pheanstalk = new \Pheanstalk\Pheanstalk($beanstalkIp);
    $pheanstalk->useTube('github-tube')->put(json_encode($event));
    $pheanstalk->useTube('testdata-tube')->put(json_encode($event));
    return new Response('Received!', 200);
});
$app->run();
<?php

//start init $pheanstalk instance
require __DIR__ . '/../vendor/autoload.php';
$pheanstalk = new Pheanstalk\Pheanstalk('beanstalkd');
//end init $pheanstalk instance
if ($pheanstalk->getConnection()->isServiceListening() === false) {
    print "Error: Cannot connect to beanstalkd.";
} else {
    print "Connected to beanstalkd.<br/><br/>";
    //start add job to queue
    $job_data = "Current timestamp: " . time();
    $pheanstalk->useTube('testqueue')->put($job_data);
    //end add job to queue
    print "Job sent data => <b>{$job_data}</b>";
}