예제 #1
0
 public function testAfterEnqueueEventCallbackFires()
 {
     $callback = 'afterEnqueueEventCallback';
     $event = 'afterEnqueue';
     Event::listen($event, array($this, $callback));
     Resque::enqueue('jobs', 'Test_Job', array('somevar'));
     $this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
 }
예제 #2
0
 public function testRecreatedJobWithTrackingStillTracksStatus()
 {
     $originalToken = Resque::enqueue('jobs', 'Test_Job', 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());
 }
예제 #3
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');
\PhpResque\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);
예제 #4
0
 public function testDequeueNonExistingItem2()
 {
     $queue = 'jobs';
     Resque::enqueue($queue, 'Test_Job_Dequeue1');
     Resque::enqueue($queue, 'Test_Job_Dequeue2');
     Resque::enqueue($queue, 'Test_Job_Dequeue3');
     $this->assertEquals(Resque::size($queue), 3);
     $test = ['Test_Job_Dequeue4', 'Test_Job_Dequeue1'];
     $this->assertEquals(Resque::dequeue($queue, $test), 1);
     $this->assertEquals(Resque::size($queue), 2);
 }
예제 #5
0
 public static function get($jobId)
 {
     $data = Resque::Redis()->get('failed:' . $jobId);
     return unserialize($data);
 }
예제 #6
0
파일: Job.php 프로젝트: RTLer/php-resque-ex
 /**
  * Find the next available job from the specified queue and return an
  * instance of Resque_Job for it.
  *
  * @param string $queue The name of the queue to check for a job in.
  * @return null|Job Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
  */
 public static function reserve($queue)
 {
     $payload = Resque::pop($queue);
     if (!is_array($payload)) {
         return false;
     }
     return new Job($queue, $payload);
 }
예제 #7
0
 /**
  * Return an object describing the job this worker is currently working on.
  *
  * @return object Object with details of current job.
  */
 public function job()
 {
     $job = Resque::redis()->get('worker:' . $this);
     if (!$job) {
         return array();
     } else {
         return json_decode($job, true);
     }
 }
예제 #8
0
 /**
  * Delete a statistic with the given name.
  *
  * @param string $stat The name of the statistic to delete.
  * @return boolean True if successful, false if not.
  */
 public static function clear($stat)
 {
     return (bool) Resque::redis()->del('stat:' . $stat);
 }
예제 #9
0
 /**
  * Stop tracking the status of a job.
  */
 public function stop()
 {
     Resque::redis()->del((string) $this);
 }
예제 #10
0
 public function testWorkerErasesItsStatsWhenShutdown()
 {
     Resque::enqueue('jobs', 'Test_Job');
     Resque::enqueue('jobs', 'Invalid_Job');
     $worker = new Worker('jobs');
     $worker->work(0);
     $worker->work(0);
     $this->assertEquals(0, $worker->getStat('processed'));
     $this->assertEquals(0, $worker->getStat('failed'));
 }