setBackend() public static method

Given a host/port combination separated by a colon, set it as the redis server that Resque will talk to.
public static setBackend ( mixed $server, integer $database )
$server mixed Host/port combination separated by a colon, DSN-formatted URI, or a callable that receives the configured database ID and returns a Resque_Redis instance, or a nested array of servers with host/port pairs.
$database integer
コード例 #1
0
 /**
  * Check that all needed and option params have been set
  *
  *
  */
 public function init()
 {
     // Ensure the composer autoloader is loaded so dependencies are loaded correctly
     require_once BASE_PATH . '/vendor/autoload.php';
     parent::init();
     $numWorkers = $this->request->getVar('count');
     if ($numWorkers > 1 && !function_exists('pcntl_fork')) {
         throw new Exception('This module need the pcntl PHP module');
     } else {
         if ($numWorkers) {
             $this->numWorkers = $numWorkers;
         }
     }
     if (php_sapi_name() !== 'cli') {
         echo 'The resque runner must be started in a CLI environment.';
         exit(1);
     }
     if (!$this->request->getVar('queue')) {
         echo "Set 'queue' parameter to containing the list of queues to work on.\n";
         exit(1);
     }
     $this->queue = $this->request->getVar('queue');
     if ($this->request->getVar('backend')) {
         Resque::setBackend($this->request->getVar('backend'));
     }
     $this->logger = new SSResqueLogger((bool) $this->request->getVar('verbose'));
 }
コード例 #2
0
 public function perform()
 {
     \Resque::setBackend('127.0.0.1:6379');
     \Resque::enqueue('default', 'ProofPilot\\Jobs\\VerificationNoticeJob', array());
     \Resque::enqueue('default', 'ProofPilot\\Jobs\\InterventionStartJob', array());
     \Resque::enqueue('default', 'ProofPilot\\Jobs\\GeneralNotificationInterventionJob', array());
 }
コード例 #3
0
ファイル: UsersHelper.php プロジェクト: Rming/novophp
 public function sendResetPasswordEmail($args)
 {
     require NOVOPHP_VENDORS_DIR . '/PHPResque/lib/Resque.php';
     date_default_timezone_set('GMT');
     Resque::setBackend(RESQUE_SERVER_REDIS);
     $jobId = Resque::enqueue("email", "ResetPasswordEmail_Job", $args, true);
     return $jobId;
 }
コード例 #4
0
ファイル: RedisTest.php プロジェクト: chrisboulton/php-resque
 /**
  * @expectedException Resque_RedisException
  */
 public function testRedisExceptionsAreSurfaced()
 {
     $mockCredis = $this->getMockBuilder('Credis_Client')->setMethods(['connect', '__call'])->getMock();
     $mockCredis->expects($this->any())->method('__call')->will($this->throwException(new CredisException('failure')));
     Resque::setBackend(function ($database) use($mockCredis) {
         return new Resque_Redis('localhost:6379', $database, $mockCredis);
     });
     Resque::redis()->ping();
 }
コード例 #5
0
ファイル: TestCase.php プロジェクト: chrisboulton/php-resque
 public function setUp()
 {
     $config = file_get_contents(REDIS_CONF);
     preg_match('#^\\s*port\\s+([0-9]+)#m', $config, $matches);
     $this->redis = new Credis_Client('localhost', $matches[1]);
     Resque::setBackend('redis://localhost:' . $matches[1]);
     // Flush redis
     $this->redis->flushAll();
 }
コード例 #6
0
ファイル: JobTest.php プロジェクト: chrisboulton/php-resque
 /**
  * @expectedException Resque_RedisException
  */
 public function testRedisErrorThrowsExceptionOnJobCreation()
 {
     $mockCredis = $this->getMockBuilder('Credis_Client')->setMethods(['connect', '__call'])->getMock();
     $mockCredis->expects($this->any())->method('__call')->will($this->throwException(new CredisException('failure')));
     Resque::setBackend(function ($database) use($mockCredis) {
         return new Resque_Redis('localhost:6379', $database, $mockCredis);
     });
     Resque::enqueue('jobs', 'This is a test');
 }
コード例 #7
0
 public function actionQueue()
 {
     $class = Yii::$app->getRequest()->get('class');
     if (empty($class)) {
         exit('Empty Job Class !!!');
     }
     \Resque::setBackend('127.0.0.1:6379');
     $args = array('time' => time(), 'array' => array('test' => 'test'));
     $jobId = \Resque::enqueue('mail', '\\i\\models\\jobs\\' . $class, $args, true);
     $this->redirect(Url::toRoute(['queue/queues'], true));
 }
コード例 #8
0
ファイル: Client.php プロジェクト: stevetauber/php-gcm-queue
 /**
  * @param string $serverApiKey An API key that gives the application server authorized access to Google services.
  * @param string $sendJob Class name of the Job that extends DefaultSendJob.
  * @param mixed  $server Host/port combination separated by a colon, DSN-formatted URI, or a nested array of
  *                       servers with host/port pairs.
  * @param int    $database ID of Redis Database to select.
  * @param string $queueName Queue Name
  * @param mixed  $gcmUrl GCM URL.
  */
 public static function configure($serverApiKey, $sendJob, $server = 'localhost:6379', $database = 0, $queueName = null, $gcmUrl = false)
 {
     \Resque::setBackend($server, $database);
     self::$serverApiKey = $serverApiKey;
     self::$sendJob = $sendJob;
     if ($queueName) {
         self::$queueName = $queueName;
     }
     if ($gcmUrl) {
         self::$gcmUrl = $gcmUrl;
     }
 }
コード例 #9
0
 /**
  * initialize plugin
  *
  * @access public
  * @return void
  */
 public function initialize()
 {
     if ($this->configuration instanceof sfApplicationConfiguration) {
         $configCache = $this->configuration->getConfigCache();
         $configCache->registerConfigHandler(self::CONFIG_PATH, 'sfResqueConfigHandler');
         $config = (include $configCache->checkConfig(self::CONFIG_PATH));
     } else {
         $configPaths = $this->configuration->getConfigPaths(self::CONFIG_PATH);
         $config = sfResqueConfigHandler::getConfiguration($configPaths);
     }
     Resque::setBackend($config['server']);
 }
コード例 #10
0
 public function __construct(array $options)
 {
     $this->defaultQueue = $options['default_queue'];
     $this->setKernelOptions($options['kernel_options']);
     $this->debug = $options['debug'];
     if (!$this->debug) {
         \Resque::setBackend("{$options['host']}:{$options['port']}");
         if (isset($options['prefix'])) {
             \Resque_Redis::prefix($options['prefix']);
         }
     }
     $this->trackStatus = $options['track_status'];
 }
コード例 #11
0
 /**
  * @param string $host
  * @param int $port
  * @param array $kernelOptions
  * @param string $defaultQueue
  * @param bool $debug if debug is true then no calls to Resque will be made
  * @param boolean $trackStatus Set to true to be able to monitor the status of jobs
  */
 public function __construct($host, $port, $kernelOptions, $defaultQueue, $prefix, $debug, $trackStatus)
 {
     $this->defaultQueue = $defaultQueue;
     $this->setKernelOptions($kernelOptions);
     $this->debug = $debug;
     if (!$debug) {
         \Resque::setBackend("{$host}:{$port}");
         if ($prefix) {
             \Resque_Redis::prefix($prefix);
         }
     }
     $this->trackStatus = $trackStatus;
 }
コード例 #12
0
ファイル: Queue.php プロジェクト: hlegius/PHPResqueBundle
 public static function add($job_name, $queue_name, $args = array())
 {
     \Resque::setBackend('127.0.0.1:6379');
     if (strpos($queue_name, ':') !== false) {
         list($namespace, $queue_name) = explode(':', $queue_name);
         \Resque_Redis::prefix($namespace);
     }
     try {
         $klass = new \ReflectionClass($job_name);
         $jobId = \Resque::enqueue($queue_name, $klass->getName(), $args, true);
         return $jobId;
     } catch (\ReflectionException $rfe) {
         throw new \RuntimeException($rfe->getMessage());
     }
 }
 /**
  * Initialize the class and set its properties.
  *
  * @since    1.0.0
  * @param      string    $plugin_name       The name of this plugin.
  * @param      string    $version    The version of this plugin.
  */
 public function __construct($plugin_name, $version)
 {
     $this->plugin_name = $plugin_name;
     $this->version = $version;
     $this->redis = new Predis\Client(['scheme' => 'tcp', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'password' => REDIS_PASSWORD]);
     $this->blog_id = get_current_blog_id();
     if (function_exists('get_blog_details')) {
         $details = get_blog_details($this->blog_id, 'domain', false);
         $domain = $details->domain;
         $sub_domain = explode(".", $domain)[0];
         $this->sub_domain = $sub_domain;
     }
     Resque::setBackend(REDIS_HOST . ":" . REDIS_PORT, REDIS_DB);
     Resque_Event::listen('afterPerform', array('RooftopJob', 'afterPerform'));
 }
コード例 #14
0
ファイル: RResque.php プロジェクト: rolies106/yii2resque
 /**
  * Initializes the connection.
  */
 public function init()
 {
     parent::init();
     if (!class_exists('RResqueAutoloader', false)) {
         # Turn off our amazing library autoload
         spl_autoload_unregister(array('YiiBase', 'autoload'));
         # Include Autoloader library
         include dirname(__FILE__) . '/RResqueAutoloader.php';
         # Run request autoloader
         RResqueAutoloader::register();
         # Give back the power to Yii
         spl_autoload_register(array('YiiBase', 'autoload'));
     }
     Resque::setBackend($this->server . ':' . $this->port, $this->database, $this->password);
     if ($this->prefix) {
         Resque::redis()->prefix($this->prefix);
     }
 }
コード例 #15
0
ファイル: Status.php プロジェクト: hlegius/PHPResqueBundle
 public static function update($status, $to_job_id, $namespace)
 {
     \Resque::setBackend('127.0.0.1:6379');
     if (!empty($namespace)) {
         \Resque_Redis::prefix($namespace);
     }
     $job = new \Resque_Job_Status($to_job_id);
     if (!$job->get()) {
         throw new \RuntimeException("Job {$to_job_id} was not found");
     }
     $class = new \ReflectionObject($job);
     foreach ($class->getConstants() as $constant_value) {
         if ($constant_value == $status) {
             $job->update($status);
             return true;
         }
     }
     return false;
 }
コード例 #16
0
 public function daemon()
 {
     \Resque::setBackend('127.0.0.1:6379');
     if (strpos($this->queue, ':') !== false) {
         list($namespace, $queue) = explode(':', $this->queue);
         \Resque_Redis::prefix($namespace);
         $this->queue = $queue;
     }
     if ($this->getForkInstances() > 1) {
         for ($i = 0; $i < $this->getForkInstances(); ++$i) {
             $pid = pcntl_fork();
             if ($pid == -1) {
                 throw new \RuntimeException("Could not fork worker {$i}");
             }
             $this->work();
             break;
         }
     } else {
         $this->work();
     }
 }
コード例 #17
0
ファイル: JobTest.php プロジェクト: misterniall/php-resque-ex
 public function testJobWithNamespace()
 {
     Resque::setBackend(REDIS_HOST, REDIS_DATABASE, 'php');
     $queue = 'jobs';
     $payload = array('another_value');
     Resque::enqueue($queue, 'Test_Job_With_TearDown', $payload);
     $this->assertEquals(Resque::queues(), array('jobs'));
     $this->assertEquals(Resque::size($queue), 1);
     Resque::setBackend(REDIS_HOST, REDIS_DATABASE, REDIS_NAMESPACE);
     $this->assertEquals(Resque::size($queue), 0);
 }
コード例 #18
0
ファイル: QueuesAction.php プロジェクト: neilmillard/fxtrader
 public function workers(Request $request, Response $response, array $args)
 {
     $data = [];
     $settings = loadsettings();
     $REDIS_BACKEND = $settings['resque']['REDIS_BACKEND'];
     if (!empty($REDIS_BACKEND)) {
         \Resque::setBackend($REDIS_BACKEND);
     }
     $workerlist = \Resque_Worker::all();
     $workers = [];
     foreach ($workerlist as $worker) {
         $job = $worker->job();
         if (empty($job)) {
             $job = "Idle";
         }
         $workers[] = ['name' => (string) $worker, 'job' => $job];
     }
     $data['workers'] = $workers;
     $this->view->render($response, 'workers.twig', $data);
     return $response;
 }
コード例 #19
0
ファイル: bootstrap.php プロジェクト: sprytechies/loctogo
    echo "Cannot find redis-server in path. Please make sure redis is installed.\n";
    exit(1);
}
exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar);
usleep(500000);
if ($returnVar != 0) {
    echo "Cannot start redis-server.\n";
    exit(1);
}
// Get redis port from conf
$config = file_get_contents(REDIS_CONF);
if (!preg_match('#^\\s*port\\s+([0-9]+)#m', $config, $matches)) {
    echo "Could not determine redis port from redis.conf";
    exit(1);
}
Resque::setBackend('localhost:' . $matches[1]);
// Shutdown
function killRedis($pid)
{
    if (getmypid() !== $pid) {
        return;
        // don't kill from a forked worker
    }
    $config = file_get_contents(REDIS_CONF);
    if (!preg_match('#^\\s*pidfile\\s+([^\\s]+)#m', $config, $matches)) {
        return;
    }
    $pidFile = TEST_MISC . '/' . $matches[1];
    if (file_exists($pidFile)) {
        $pid = trim(file_get_contents($pidFile));
        posix_kill((int) $pid, 9);
コード例 #20
0
<?php

// getenv — 获取一个环境变量的值
// 从下面的Code中可以看到相应的环境变量有:QUEUE/REDIS_BACKEND/LOGGING/VERBOSE/VVERBOSE/APP_INCLUDE/INTERVAL/COUNT/PIDFILE
// QUEUE表示队列的名称,可以有多个(用逗号分隔),*表示所有
$QUEUE = getenv('QUEUE');
if (empty($QUEUE)) {
    die("Set QUEUE env var containing the list of queues to work.\n");
}
require_once 'lib/Resque.php';
require_once 'lib/Resque/Worker.php';
// REDIS_BACKEND表示Redis的配置
$REDIS_BACKEND = getenv('REDIS_BACKEND');
if (!empty($REDIS_BACKEND)) {
    Resque::setBackend($REDIS_BACKEND);
}
$logLevel = 0;
// LOGGING/VERBOSE/VVERBOSE表示打印log的级别
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if (!empty($LOGGING) || !empty($VERBOSE)) {
    // 只打印message
    $logLevel = Resque_Worker::LOG_NORMAL;
} else {
    if (!empty($VVERBOSE)) {
        // 只打印message和时间
        $logLevel = Resque_Worker::LOG_VERBOSE;
    }
}
// APP_INCLUDE表示需要额外引入的文件
コード例 #21
0
exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar);
usleep(500000);
if ($returnVar != 0) {
    echo "Cannot start redis-server.\n";
    exit(1);
}
// Get redis port from conf
$config = file_get_contents(REDIS_CONF);
if (!preg_match('#^\\s*port\\s+([0-9]+)#m', $config, $matches)) {
    echo "Could not determine redis port from redis.conf";
    exit(1);
}
define('REDIS_HOST', 'localhost:' . $matches[1]);
define('REDIS_DATABASE', 7);
define('REDIS_NAMESPACE', 'testResque');
Resque::setBackend(REDIS_HOST, REDIS_DATABASE, REDIS_NAMESPACE);
// Shutdown
function killRedis($pid)
{
    if (getmypid() !== $pid) {
        return;
        // don't kill from a forked worker
    }
    $config = file_get_contents(REDIS_CONF);
    if (!preg_match('#^\\s*pidfile\\s+([^\\s]+)#m', $config, $matches)) {
        return;
    }
    $pidFile = TEST_MISC . '/' . $matches[1];
    if (file_exists($pidFile)) {
        $pid = trim(file_get_contents($pidFile));
        posix_kill((int) $pid, 9);
コード例 #22
0
    require_once $RESQUE_PHP;
} else {
    if (!class_exists('Resque')) {
        require_once 'Resque/Resque.php';
    }
}
// Load resque-scheduler
require_once dirname(__FILE__) . '/lib/ResqueRepeater.php';
require_once dirname(__FILE__) . '/lib/ResqueRepeater/Worker.php';
$REDIS_BACKEND = getenv('REDIS_BACKEND');
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
if (!empty($REDIS_BACKEND)) {
    if (empty($REDIS_BACKEND_DB)) {
        Resque::setBackend($REDIS_BACKEND);
    } else {
        Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
    }
}
// Set log level for resque-scheduler
$logLevel = 0;
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if (!empty($LOGGING) || !empty($VERBOSE)) {
    $logLevel = ResqueRepeater_Worker::LOG_NORMAL;
} else {
    if (!empty($VVERBOSE)) {
        $logLevel = ResqueRepeater_Worker::LOG_VERBOSE;
    }
}
// Check for jobs every $interval seconds
コード例 #23
0
ファイル: QueueController.php プロジェクト: zhangsong/yii
 public function actionRun()
 {
     $QUEUE = getenv('QUEUE');
     if (empty($QUEUE)) {
         die("Set QUEUE env var containing the list of queues to work.\n");
     }
     $REDIS_BACKEND = getenv('REDIS_BACKEND');
     if (!empty($REDIS_BACKEND)) {
         \Resque::setBackend($REDIS_BACKEND);
     }
     $logLevel = 0;
     $LOGGING = getenv('LOGGING');
     $VERBOSE = getenv('VERBOSE');
     $VVERBOSE = getenv('VVERBOSE');
     if (!empty($LOGGING) || !empty($VERBOSE)) {
         $logLevel = \Resque_Worker::LOG_NORMAL;
     } else {
         if (!empty($VVERBOSE)) {
             $logLevel = \Resque_Worker::LOG_VERBOSE;
         }
     }
     $APP_INCLUDE = getenv('APP_INCLUDE');
     if ($APP_INCLUDE) {
         if (!file_exists($APP_INCLUDE)) {
             die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
         }
         require_once $APP_INCLUDE;
     }
     $interval = 5;
     $INTERVAL = getenv('INTERVAL');
     if (!empty($INTERVAL)) {
         $interval = $INTERVAL;
     }
     $count = 1;
     $COUNT = getenv('COUNT');
     if (!empty($COUNT) && $COUNT > 1) {
         $count = $COUNT;
     }
     if ($count > 1) {
         for ($i = 0; $i < $count; ++$i) {
             $pid = pcntl_fork();
             if ($pid == -1) {
                 die("Could not fork worker " . $i . "\n");
             } else {
                 if (!$pid) {
                     $queues = explode(',', $QUEUE);
                     $worker = new \Resque_Worker($queues);
                     $worker->logLevel = $logLevel;
                     fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
                     $worker->work($interval);
                     break;
                 }
             }
         }
     } else {
         $queues = explode(',', $QUEUE);
         $worker = new \Resque_Worker($queues);
         $worker->logLevel = $logLevel;
         $PIDFILE = getenv('PIDFILE');
         if ($PIDFILE) {
             file_put_contents($PIDFILE, getmypid()) or die('Could not write PID information to ' . $PIDFILE);
         }
         fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
         $worker->work($interval);
     }
 }
コード例 #24
0
ファイル: queue.php プロジェクト: cunwang/msgque-resque
<?php

require realpath(dirname(__FILE__) . "/../MsgQueue.php");
Resque::setBackend('localhost:6379');
$args = array('name' => 'Chris');
echo Resque::enqueue('QUEUE-Test', '\\app\\jobs\\My_Job', $args);
コード例 #25
0
ファイル: Fresque.php プロジェクト: neoseeker/fresque
 public function __construct()
 {
     $this->command = array_splice($_SERVER['argv'], 1, 1);
     $this->command = empty($this->command) ? null : $this->command[0];
     if ($this->command == 'start') {
         $this->command = 'load';
     }
     $this->input = new \ezcConsoleInput();
     $this->output = new \ezcConsoleOutput();
     $helpOption = $this->input->registerOption(new \ezcConsoleOption('h', 'help'));
     $helpOption->isHelpOption = true;
     $this->input->registerOption(new \ezcConsoleOption('u', 'user', \ezcConsoleInput::TYPE_STRING, null, false, 'User running the workers', 'User running the workers'));
     $this->input->registerOption(new \ezcConsoleOption('q', 'queue', \ezcConsoleInput::TYPE_STRING, null, false, 'Name of the queue. If multiple queues, separate with comma.', 'Name of the queue. If multiple queues, separate with comma.'));
     $this->input->registerOption(new \ezcConsoleOption('i', 'interval', \ezcConsoleInput::TYPE_INT, null, false, 'Pause time in seconds between each worker round', 'Pause time in seconds between each worker round'));
     $this->input->registerOption(new \ezcConsoleOption('n', 'workers', \ezcConsoleInput::TYPE_INT, null, false, 'Number of workers to create', 'Number of workers to create'));
     $this->input->registerOption(new \ezcConsoleOption('f', 'force', \ezcConsoleInput::TYPE_NONE, null, false, 'Force workers shutdown, forcing all the current jobs to finish (and fail)', 'Force workers shutdown, forcing all the current jobs to finish (and fail)'));
     $this->input->registerOption(new \ezcConsoleOption('v', 'verbose', \ezcConsoleInput::TYPE_NONE, null, false, 'Log more verbose informations', 'Log more verbose informations'));
     $this->input->registerOption(new \ezcConsoleOption('g', 'debug', \ezcConsoleInput::TYPE_NONE, null, false, 'Print debug informations', 'Print debug informations'));
     $this->input->registerOption(new \ezcConsoleOption('s', 'host', \ezcConsoleInput::TYPE_STRING, null, false, 'Redis server hostname', 'Redis server hostname (eg. localhost, 127.0.0.1, etc ...)'));
     $this->input->registerOption(new \ezcConsoleOption('p', 'port', \ezcConsoleInput::TYPE_INT, null, false, 'Redis server port', 'Redis server port'));
     $this->input->registerOption(new \ezcConsoleOption('l', 'log', \ezcConsoleInput::TYPE_STRING, null, false, 'Log file path', 'Absolute path to the log file'));
     $this->input->registerOption(new \ezcConsoleOption('b', 'lib', \ezcConsoleInput::TYPE_STRING, null, false, 'PHPresque library path', 'Absolute path to your PHPResque library'));
     $this->input->registerOption(new \ezcConsoleOption('a', 'autoloader', \ezcConsoleInput::TYPE_STRING, null, false, 'Application autoloader path', 'Absolute path to your application autoloader file'));
     $this->input->registerOption(new \ezcConsoleOption('c', 'config', \ezcConsoleInput::TYPE_STRING, null, false, 'Configuration file path', 'Absolute path to your configuration file'));
     $this->input->registerOption(new \ezcConsoleOption('d', 'loghandler', \ezcConsoleInput::TYPE_STRING, null, false, 'Log Handler', 'Handler used for logging'));
     $this->input->registerOption(new \ezcConsoleOption('r', 'handlertarget', \ezcConsoleInput::TYPE_STRING, null, false, 'Log Handler options', 'Arguments used for initializing the handler'));
     $this->input->registerOption(new \ezcConsoleOption('w', 'all', \ezcConsoleInput::TYPE_NONE, null, false, 'Stop all workers', 'Stop all workers'));
     $this->output->formats->title->color = 'yellow';
     $this->output->formats->title->style = 'bold';
     $this->output->formats->subtitle->color = 'blue';
     $this->output->formats->subtitle->style = 'bold';
     $this->output->formats->warning->color = 'red';
     $this->output->formats->bold->style = 'bold';
     $this->output->formats->highlight->color = 'blue';
     $this->output->formats->success->color = 'green';
     $this->output->formats->success->style = 'normal';
     try {
         $this->input->process();
     } catch (\ezcConsoleException $e) {
         $this->output->outputLine($e->getMessage() . "\n", 'failure');
         die;
     }
     $settings = $this->loadSettings();
     $args = $this->input->getArguments();
     $globalOptions = array('s' => 'host', 'p' => 'port', 'b' => 'path', 'c' => 'path', 'a' => 'path', 'd' => 'handler', 'r' => 'args,');
     $commandTree = array('start' => array('help' => 'Start a new worker', 'options' => array('u' => 'username', 'q' => 'queue name', 'i' => 'num', 'n' => 'num', 'l' => 'path', 'v', 'g')), 'stop' => array('help' => 'Shutdown all workers', 'options' => array('f', 'w', 'g')), 'restart' => array('help' => 'Restart all workers', 'options' => array()), 'load' => array('help' => 'Load workers defined in your configuration file', 'options' => array('l')), 'tail' => array('help' => 'Monitor the log file', 'options' => array()), 'enqueue' => array('help' => 'Enqueue a new job', 'options' => array()), 'stats' => array('help' => 'Display resque statistics', 'options' => array()), 'test' => array('help' => 'Test your fresque configuration file', 'options' => array('u' => 'username', 'q' => 'queue name', 'i' => 'num', 'n' => 'num', 'l' => 'path')));
     if ($this->command === null || !method_exists($this, $this->command)) {
         $this->outputTitle('Welcome to Fresque');
         $this->output->outputLine('Fresque ' . Fresque::VERSION . ' by Wan Chen (Kamisama) (2013)');
         if (!method_exists($this, $this->command) && $this->command !== null && $this->command !== '--help') {
             $this->output->outputLine("\nUnrecognized command : " . $this->command, 'failure');
         }
         $this->output->outputLine();
         $this->output->outputLine("Available commands\n", 'subtitle');
         foreach ($commandTree as $name => $opt) {
             $this->output->outputText($name . str_repeat(' ', 15 - strlen($name)), 'bold');
             $this->output->outputText($opt['help'] . "\n");
         }
         $this->output->outputLine("\nUse <command> --help to get more infos about a command\n");
     } else {
         if ($helpOption->value === true) {
             $this->output->outputLine();
             $this->output->outputLine($commandTree[$this->command]['help']);
             if (!empty($commandTree[$this->command]['options'])) {
                 $this->output->outputLine("\nAvailable options\n", 'subtitle');
                 foreach ($commandTree[$this->command]['options'] as $name => $arg) {
                     $opt = $this->input->getOption(is_numeric($name) ? $arg : $name);
                     $o = (!empty($opt->short) ? '-' . $opt->short : '  ') . ' ' . (is_numeric($name) ? '' : '<' . $arg . '>');
                     $this->output->outputLine($o . str_repeat(' ', 15 - strlen($o)) . " --" . $opt->long . str_repeat(' ', 15 - strlen($opt->long)) . " {$opt->longhelp}");
                 }
             }
             $this->output->outputLine("\nGlobal options\n", 'subtitle');
             foreach ($globalOptions as $name => $arg) {
                 $opt = $this->input->getOption(is_numeric($name) ? $arg : $name);
                 $o = '-' . $opt->short . ' ' . (is_numeric($name) ? '' : '<' . $arg . '>');
                 $this->output->outputLine($o . str_repeat(' ', 15 - strlen($o)) . " --" . $opt->long . str_repeat(' ', 15 - strlen($opt->long)) . " {$opt->longhelp}");
             }
             $this->output->outputLine();
         } else {
             $allowed = array_merge($commandTree[$this->command]['options'], $globalOptions);
             foreach ($allowed as $name => &$arg) {
                 if (!is_numeric($name)) {
                     $arg = $name;
                 }
             }
             $unrecognized = array_diff(array_keys($this->input->getOptionValues()), array_values($allowed));
             if (!empty($unrecognized)) {
                 $this->output->outputLine('Invalid options ' . implode(', ', array_map(function ($opt) {
                     return '-' . $opt;
                 }, $unrecognized)) . ' will be ignored', 'warning');
             }
             \Resque::setBackend($this->runtime['Redis']['host'] . ':' . $this->runtime['Redis']['port'], $this->runtime['Redis']['database'], $this->runtime['Redis']['namespace']);
             $this->{$this->command}();
         }
     }
 }
コード例 #26
0
ファイル: Queue.php プロジェクト: zlik/magento-resque
 public function __construct($redisBackend = 'localhost:6379')
 {
     Resque::setBackend($redisBackend);
     $this->queriesPatterns = array('/CREATE INDEX `\\w+` ON `(\\w+)`/', '/DROP INDEX `\\w+` ON `(\\w+)`/', '/CREATE TABLE `(\\w+)`/', '/DROP TABLE `(\\w+)`/', '/ALTER TABLE `(\\w+)`/', '/TRUNCATE TABLE `(\\w+)`/');
 }
コード例 #27
0
} elseif (!class_exists('Resque')) {
    // Otherwise, if we have no Resque then assume it is in the include path
    require_once 'Resque/Resque.php';
}
// Load resque-scheduler
require_once dirname(dirname(__FILE__)) . '/lib/ResqueScheduler/ResqueScheduler.php';
require_once dirname(dirname(__FILE__)) . '/lib/ResqueScheduler/Worker.php';
$REDIS_BACKEND = getenv('REDIS_BACKEND');
$REDIS_DATABASE = getenv('REDIS_DATABASE');
$REDIS_NAMESPACE = getenv('REDIS_NAMESPACE');
$REDIS_PASSWORD = getenv('REDIS_PASSWORD') == '' ? null : getenv('REDIS_PASSWORD');
$LOG_HANDLER = getenv('LOGHANDLER');
$LOG_HANDLER_TARGET = getenv('LOGHANDLERTARGET');
$logger = new MonologInit\MonologInit($LOG_HANDLER, $LOG_HANDLER_TARGET);
if (!empty($REDIS_BACKEND)) {
    Resque::setBackend($REDIS_BACKEND, $REDIS_DATABASE, $REDIS_NAMESPACE, $REDIS_PASSWORD);
}
// Set log level for resque-scheduler
$logLevel = 0;
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if (!empty($LOGGING) || !empty($VERBOSE)) {
    $logLevel = ResqueScheduler\Worker::LOG_NORMAL;
} elseif (!empty($VVERBOSE)) {
    $logLevel = ResqueScheduler\Worker::LOG_VERBOSE;
}
// Load the user's application if one exists
$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
    if (!file_exists($APP_INCLUDE)) {
コード例 #28
0
 function initialize(&$controller, $settings = array())
 {
     Configure::load('Resque.resque');
     Resque::setBackend(Configure::read('Resque.Redis.host') . ':' . Configure::read('Resque.Redis.port'), Configure::read('Resque.Redis.port'));
 }
コード例 #29
0
<?php

/**
 * Created by PhpStorm.
 * User: viniciusthiengo
 * Date: 7/23/15
 * Time: 10:50 AM
 */
require '../vendor/autoload.php';
require 'EchoData.php';
//include
date_default_timezone_set('GMT');
Resque::setBackend('127.0.0.1:6379');
$args = array('name' => 'Thiengo');
$jobId = Resque::enqueue('default', 'EchoData', $args, true);
echo "Queued job " . $jobId . "<br><br>";
$status = new Resque_Job_Status($jobId);
if (!$status->isTracking()) {
    die("Resque is not tracking the status of this job.\n");
}
echo $status . '<br><br>';
$jobId = Resque::enqueue('cms26', 'EchoData2', $args);
//exec('echo "create-file.php" | atnow');
//exec('php "create-file.php" | atnow');
echo 'file has being created <br><br>';
//Resque::pop('notification');
echo Resque::size('default');
print_r(Resque::queues());
コード例 #30
0
 /**
  * This command echoes what you have entered as the message.
  * @param string $message the message to be echoed.
  */
 public function actionIndex()
 {
     $includeFiles = getenv('INCLUDE_FILES');
     if ($includeFiles) {
         $includeFiles = explode(',', $includeFiles);
         foreach ($includeFiles as $file) {
             require_once $file;
         }
     }
     if (file_exists(Yii::getAlias('@app') . '/config/console.php')) {
         // Yii2-Basic
         $config = (require Yii::getAlias('@app') . '/config/console.php');
     } else {
         // Yii2-Advance
         $config = (require Yii::getAlias('@app') . '/config/main.php');
     }
     $application = new \yii\console\Application($config);
     # Turn off our amazing library autoload
     spl_autoload_unregister(array('Yii', 'autoload'));
     if (file_exists(Yii::getAlias('@vendor') . '/resque/yii2-resque/ResqueAutoloader.php')) {
         // Yii2-Basic
         require_once Yii::getAlias('@vendor') . '/resque/yii2-resque/ResqueAutoloader.php';
     } else {
         // Yii2-Advance
         require_once Yii::getAlias('@app') . '/../vendor/resque/yii2-resque/ResqueAutoloader.php';
     }
     ResqueAutoloader::register();
     # Give back the power to Yii
     spl_autoload_register(array('Yii', 'autoload'));
     $QUEUE = getenv('QUEUE');
     if (empty($QUEUE)) {
         die("Set QUEUE env var containing the list of queues to work.\n");
     }
     $REDIS_BACKEND = getenv('REDIS_BACKEND');
     $REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
     $REDIS_AUTH = getenv('REDIS_AUTH');
     if (!empty($REDIS_BACKEND)) {
         $REDIS_BACKEND_DB = !empty($REDIS_BACKEND_DB) ? $REDIS_BACKEND_DB : 0;
         Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB, $REDIS_AUTH);
     }
     $logLevel = 0;
     $LOGGING = getenv('LOGGING');
     $VERBOSE = getenv('VERBOSE');
     $VVERBOSE = getenv('VVERBOSE');
     if (!empty($LOGGING) || !empty($VERBOSE)) {
         $logLevel = Resque_Worker::LOG_NORMAL;
     } else {
         if (!empty($VVERBOSE)) {
             $logLevel = Resque_Worker::LOG_VERBOSE;
         }
     }
     $logger = null;
     $LOG_HANDLER = getenv('LOGHANDLER');
     $LOG_HANDLER_TARGET = getenv('LOGHANDLERTARGET');
     if (class_exists('MonologInit_MonologInit')) {
         if (!empty($LOG_HANDLER) && !empty($LOG_HANDLER_TARGET)) {
             $logger = new MonologInit_MonologInit($LOG_HANDLER, $LOG_HANDLER_TARGET);
         } else {
             fwrite(STDOUT, '*** loghandler or logtarget is not set.' . "\n");
         }
     } else {
         fwrite(STDOUT, '*** MonologInit_MonologInit logger cannot be found, continue without loghandler.' . "\n");
     }
     $interval = 5;
     $INTERVAL = getenv('INTERVAL');
     if (!empty($INTERVAL)) {
         $interval = $INTERVAL;
     }
     $count = 1;
     $COUNT = getenv('COUNT');
     if (!empty($COUNT) && $COUNT > 1) {
         $count = $COUNT;
     }
     $PREFIX = getenv('PREFIX');
     if (!empty($PREFIX)) {
         fwrite(STDOUT, '*** Prefix set to ' . $PREFIX . "\n");
         Resque::redis()->prefix($PREFIX);
     }
     if ($count > 1) {
         for ($i = 0; $i < $count; ++$i) {
             $pid = Resque::fork();
             if ($pid == -1) {
                 die("Could not fork worker " . $i . "\n");
             } else {
                 if (!$pid) {
                     startWorker($QUEUE, $logLevel, $logger, $interval);
                     break;
                 }
             }
         }
     } else {
         $PIDFILE = getenv('PIDFILE');
         if ($PIDFILE) {
             file_put_contents($PIDFILE, getmypid()) or die('Could not write PID information to ' . $PIDFILE);
         }
         $this->startWorker($QUEUE, $logLevel, $logger, $interval);
     }
 }