コード例 #1
0
ファイル: helpers.php プロジェクト: binaryvo/qiresizer
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;
}
コード例 #2
0
ファイル: beanstalk.php プロジェクト: songliang89/my-ci
 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);
 }
コード例 #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());
 }
コード例 #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;
 }
コード例 #5
0
ファイル: index.php プロジェクト: agildehaus/beanstalker
<?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) {
コード例 #6
0
ファイル: pheanstalk.php プロジェクト: josegonzalez/Queue
<?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));
コード例 #7
0
ファイル: index.php プロジェクト: devboard/devboard-notify
<?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();
コード例 #8
0
<?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>";
}