コード例 #1
0
 public function testAfterEnqueueEventCallbackFires()
 {
     $callback = 'afterEnqueueEventCallback';
     $event = 'afterEnqueue';
     Event::listen($event, array($this, $callback));
     Resque::enqueue('jobs', TestJob::className(), array('somevar'));
     $this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
 }
コード例 #2
0
ファイル: Worker.php プロジェクト: shonm/php-resque-scheduler
 /**
  * Schedule all of the delayed jobs for a given timestamp.
  *
  * Searches for all items for a given timestamp, pulls them off the list of
  * delayed jobs and pushes them across to Resque.
  *
  * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule.
  */
 public function enqueueDelayedItemsForTimestamp($timestamp)
 {
     $item = null;
     while ($item = Scheduler::nextItemForTimestamp($timestamp)) {
         $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]');
         if (!empty($item['args'])) {
             $item['args'] = reset($item['args']);
         }
         Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args']));
         Resque::enqueue($item['queue'], $item['class'], $item['args']);
     }
 }
コード例 #3
0
 public function testRecreatedJobWithTrackingStillTracksStatus()
 {
     $originalToken = Resque::enqueue('jobs', TestJob::className(), null, true);
     $job = $this->worker->reserve();
     // Mark this job as being worked on to ensure that the new status is still
     // waiting.
     $this->worker->workingOn($job);
     // Now recreate it
     $newToken = $job->recreate();
     // Make sure we've got a new job returned
     $this->assertNotEquals($originalToken, $newToken);
     // Now check the status of the new job
     $newJob = Job::reserve('jobs');
     $this->assertEquals(Status::STATUS_WAITING, $newJob->getStatus());
 }
コード例 #4
0
ファイル: InitResque.php プロジェクト: junthink/resque
 /**
  * Create a new job and save it to the specified queue.
  *
  * @param string $queue The name of the queue to place the job in.
  * @param string $class The name of the class that contains the code to execute the job.
  * @param array $args Any optional arguments that should be passed when the job is executed.
  *
  * @return string
  */
 public function createJob($queue, $class, $args = [], $track_status = false)
 {
     return Resque::enqueue($queue, $class, $args, $track_status);
 }
コード例 #5
0
 public function testJobWithNamespace()
 {
     Redis::prefix('php');
     $queue = 'jobs';
     $payload = array('another_value');
     Resque::enqueue($queue, JobWithTearDown::className(), $payload);
     $this->assertEquals(Resque::queues(), array('jobs'));
     $this->assertEquals(Resque::size($queue), 1);
     Redis::prefix('resque');
     $this->assertEquals(Resque::size($queue), 0);
 }
コード例 #6
0
<?php

require_once __DIR__ . '/../autoload.php';
use resque\Resque;
if (empty($argv[1])) {
    die('Specify the name of a job to add. e.g, php queue.php PHP_Job');
}
date_default_timezone_set('GMT');
// Resque::setBackend('127.0.0.1:6379', 0, 'your password');
Resque::setBackend('127.0.0.1:6379');
$args = array('time' => time(), 'array' => array('test' => 'test'));
$jobId = Resque::enqueue('default', $argv[1], $args, true);
echo "Queued job " . $jobId . "\n\n";
コード例 #7
0
ファイル: ErrorLog.php プロジェクト: huang-sh/yaf.app
 /**
  * 异常日志入队列
  *
  * @access public
  * @return void
  */
 public function errorLog()
 {
     if (isset(Application::app()->getConfig()->application->queue) && isset(Application::app()->getConfig()->application->queue->redis) && isset(Application::app()->getConfig()->application->queue->log)) {
         $queue = Application::app()->getConfig()->application->queue->toArray();
         $redis_config = $queue['redis'];
         $server = $redis_config['host'] . ':' . $redis_config['port'];
         $database = isset($redis_config['database']) ? $redis_config['database'] : null;
         Resque::setBackend($server, $database);
         $args = array('module' => $queue['log']['module'], 'controller' => $queue['log']['controller'], 'action' => $queue['log']['action'], 'args' => $this->toArray());
         $queue_name = Application::app()->getConfig()->application->queue->log->name;
         Resque::enqueue($queue_name, 'Resque\\Job\\YafCLIRequest', $args, true);
     }
 }
コード例 #8
0
 public function testWorkerErasesItsStatsWhenShutdown()
 {
     Resque::enqueue('jobs', TestJob::className());
     Resque::enqueue('jobs', '\\resque\\test\\job\\InvalidJob');
     $worker = new Worker('jobs');
     $worker->work(0);
     $worker->work(0);
     $this->assertEquals(0, $worker->getStat('processed'));
     $this->assertEquals(0, $worker->getStat('failed'));
 }