/**
  * @test
  */
 public function it_sends_remove_file_command_to_file_remover_via_php_resque()
 {
     $this->assertTrue(file_exists($this->testFile));
     $commandBus = new CommandBus();
     $commandRouter = new CommandRouter();
     $messageDispatcher = new MessageDispatcher(['track_job_status' => true, 'queue' => 'php-resque-test-queue']);
     $commandRouter->route('Prooph\\ServiceBusTest\\Mock\\RemoveFileCommand')->to($messageDispatcher);
     $commandBus->utilize($commandRouter);
     $commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator()));
     $jobId = null;
     $messageDispatcher->events()->attach('dispatch.post', function (EventInterface $e) use(&$jobId) {
         $jobId = $e->getParam('jobId');
     });
     $removeFile = RemoveFileCommand::fromPayload($this->testFile);
     $commandBus->dispatch($removeFile);
     $this->assertNotNull($jobId);
     $status = new \Resque_Job_Status($jobId);
     $this->assertEquals(\Resque_Job_Status::STATUS_WAITING, $status->get());
     $worker = new \Resque_Worker(array('php-resque-test-queue'));
     $worker->logLevel = 1;
     $worker->work(0);
     $worker->shutdown();
     $this->assertEquals(\Resque_Job_Status::STATUS_COMPLETE, $status->get());
     $this->assertFalse(file_exists($this->testFile));
 }
Example #2
0
 public function testStatusTrackingCanBeStopped()
 {
     Resque_Job_Status::create('test');
     $status = new Resque_Job_Status('test');
     $this->assertEquals(Resque_Job_Status::STATUS_WAITING, $status->get());
     $status->stop();
     $this->assertFalse($status->get());
 }
Example #3
0
 public static function status($token)
 {
     $status = new \Resque_Job_Status($token);
     $code = $status->get();
     if (empty($code)) {
         return self::$job_status[0];
     }
     return self::$job_status[$code];
 }
Example #4
0
 /**
  * Returns the status of the resque job
  *
  * @return string
  */
 public function ResqueStatus()
 {
     $status = new Resque_Job_Status($this->ResqueToken);
     $statusCode = $status->get();
     // The Resque job can no longer be found, fallback to the DNDeployment.Status
     if ($statusCode === false) {
         // Translate from the DNDeployment.Status to the Resque job status for UI purposes
         switch ($this->Status) {
             case 'Finished':
                 return 'Complete';
             case 'Started':
                 return 'Running';
             default:
                 return $this->Status;
         }
     }
     return self::map_resque_status($statusCode);
 }
Example #5
0
 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;
 }
Example #6
0
 public static function create($queue, $class, $args = null, $monitor = false, $method = 'fire')
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $id = md5(uniqid('', true));
     Resque::push($queue, array('class' => $class, 'method' => $method, 'args' => array($args), 'id' => $id, 'queue_time' => microtime(true)));
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
 /**
  * Enqueue a job for execution at a given timestamp.
  *
  * Identical to Resque::enqueue, however the first argument is a timestamp
  * (either UNIX timestamp in integer format or an instance of the DateTime
  * class in PHP).
  *
  * @param   DateTime|int $at            Instance of PHP DateTime object or int of UNIX timestamp.
  * @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.
  * @param   boolean      $trackStatus   Set to true to be able to monitor the status of a job.
  * @return  string                      Job ID
  */
 public static function enqueueAt($at, $queue, $class, $args = array(), $trackStatus = false)
 {
     self::validateJob($class, $queue);
     $args['id'] = md5(uniqid('', true));
     $args['s_time'] = time();
     $job = self::jobToHash($queue, $class, $args, $trackStatus);
     self::delayedPush($at, $job);
     if ($trackStatus) {
         \Resque_Job_Status::create($args['id'], Job\Status::STATUS_SCHEDULED);
     }
     \Resque_Event::trigger('afterSchedule', array('at' => $at, 'queue' => $queue, 'class' => $class, 'args' => $args));
     return $args['id'];
 }
Example #8
0
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $id = md5(uniqid('', true));
     $data = array('class' => $class, 'args' => array($args), 'id' => $id, 'closure' => true, 'queue_time' => microtime(true));
     Log::info('Push closure:' . json_encode($data));
     Resque::push($queue, $data);
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
Example #9
0
 /**
  *
  * @return string
  */
 public function ResqueStatus()
 {
     $status = new Resque_Job_Status($this->ResqueToken);
     $remap = array(Resque_Job_Status::STATUS_WAITING => "Queued", Resque_Job_Status::STATUS_RUNNING => "Running", Resque_Job_Status::STATUS_FAILED => "Failed", Resque_Job_Status::STATUS_COMPLETE => "Complete", false => "Invalid");
     return $remap[$status->get()];
 }
Example #10
0
 /**
  * Checks to see if a movie is available and returns either a link to the
  * movie if it is ready or progress information otherwise
  *
  * @return void
  */
 public function getMovieStatus()
 {
     include_once HV_ROOT_DIR . '/../src/Movie/HelioviewerMovie.php';
     require_once HV_ROOT_DIR . '/../lib/Resque.php';
     require_once HV_ROOT_DIR . '/../lib/Resque/Job.php';
     $queueNum = $this->_getQueueNum(HV_MOVIE_QUEUE, $this->_params['id']) + 1;
     // Process request
     $movie = new Movie_HelioviewerMovie($this->_params['id'], $this->_params['format']);
     $verbose = isset($this->_options['verbose']) ? $this->_options['verbose'] : false;
     if ($movie->status == 0) {
         // QUEUED
         $jobStatus = '';
         if (isset($this->_params['token']) && $this->_params['token'] != '0') {
             $status = new Resque_Job_Status($this->_params['token']);
             $jobStatus = $status->get();
         }
         $status = new Resque_Job_Status($this->_params['token']);
         $response = array('status' => $movie->status, 'statusLabel' => $this->getStatusLabel($movie->status), 'queuePosition' => $queueNum, 'currentFrame' => 0, 'jobStatus' => $jobStatus);
     } else {
         if ($movie->status == 1) {
             $current_frame = $movie->getCurrentFrame();
             $progress = $current_frame / $movie->numFrames;
             $progress = (double) number_format($progress, 3);
             $response = array('status' => $movie->status, 'statusLabel' => $this->getStatusLabel($movie->status), 'currentFrame' => $current_frame, 'numFrames' => $movie->numFrames, 'progress' => $progress, 'queuePosition' => $queueNum);
         } else {
             if ($movie->status == 2) {
                 // FINISHED
                 $response = $movie->getCompletedMovieInformation($verbose);
                 $response['statusLabel'] = $this->getStatusLabel($response['status']);
             } else {
                 if ($movie->status == 3) {
                     // ERROR
                     $response = array('status' => $movie->status, 'statusLabel' => $this->getStatusLabel($movie->status), 'error' => 'Sorry, we are unable to create your movie at ' . 'this time. Please try again later.');
                 } else {
                     $response = array('status' => $movie->status, 'statusLabel' => $this->getStatusLabel($movie->status), 'queuePosition' => $queueNum);
                 }
             }
         }
     }
     $this->_printJSON(json_encode($response));
 }
Example #11
0
 /**
  * Re-queue the current job.
  * @return string
  */
 public function recreate()
 {
     $status = new Resque_Job_Status($this->payload['id']);
     $monitor = false;
     if ($status->isTracking()) {
         $monitor = true;
         $status->update(Resque_Job_Status::STATUS_WAITING);
     }
     $this->worker->logger->log(Psr\Log\LogLevel::NOTICE, 'Requeing {job}', array('job' => $this));
     Resque::redis()->lrem('working:' . $this->queue, 0, $this->payload['id']);
     Resque_Event::trigger('onRecreate', array('job' => $this));
     return self::create($this->queue, $this->payload['class'], $this->getArguments(), $monitor, $this->payload['id']);
 }
Example #12
0
 /**
  * Check job status
  *
  * @param string $token Job token ID
  *
  * @return string Job Status
  */
 public function status($token)
 {
     $status = new Resque_Job_Status($token);
     return $status->get();
 }
Example #13
0
 public function ResqueStatus()
 {
     $status = new Resque_Job_Status($this->ResqueToken);
     return self::map_resque_status($status->get());
 }
     $commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator()));
     //The PhpResqueMessageDispatcher uses a Redis-Server to manage background jobs
     //We want to track the status of the job and therefor we use the event system of MessageDispatcher to capture the JobId
     //of a new created Job
     $jobId = null;
     //After the MessageDispatcher has done it's work, we capture the JobId with an EventListener
     $messageDispatcher->events()->attach('dispatch.post', function (EventInterface $e) use(&$jobId) {
         $jobId = $e->getParam('jobId');
     });
     //Prepare the Command
     $writeLine = WriteLine::fromPayload($_GET['write']);
     //...and send it to the message dispatcher via CommandBus
     $commandBus->dispatch($writeLine);
     echo 'Message is sent with JobId: ' . $jobId . '. You can check the status with ' . strtok($_SERVER["REQUEST_URI"], '?') . '<b>?status=' . $jobId . '</b>';
 } elseif (isset($_GET['status'])) {
     $status = new \Resque_Job_Status($_GET['status']);
     switch ($status->get()) {
         case \Resque_Job_Status::STATUS_WAITING:
             echo 'Status: waiting. If you did not start a worker yet, than open a console, and run: <b>php ' . __DIR__ . '/start-worker.php</b>';
             break;
         case \Resque_Job_Status::STATUS_RUNNING:
             echo 'Status: running. Wait a moment, the job should finish soon.';
             break;
         case \Resque_Job_Status::STATUS_COMPLETE:
             echo 'Status: complete. You should see a new line with your text, when you open: <b>' . strtok($_SERVER["REQUEST_URI"], '?') . '</b>';
             break;
         case \Resque_Job_Status::STATUS_FAILED:
             echo "Status failed: Something went wrong. Stop current worker. Try again writing some text with: " . strtok($_SERVER["REQUEST_URI"], '?') . "<b>?write=some text</b>' " . "and start a new worker with this command: <b>VVERBOSE=1 php " . __DIR__ . "/start-worker.php</b>. " . "You should be able to see the error which causes the job to fail.";
             break;
         default:
             echo "Job can not be found. Maybe you've passed an old or incomplete job id to the status param?";
Example #15
0
 public function restGetQueueJob()
 {
     $jobId = $this->params()->fromQuery('job');
     $status = new \Resque_Job_Status($jobId);
     if (!$status->isTracking()) {
         return array('status' => -1);
     }
     return array('status' => $status->get());
 }
Example #16
0
 /**
  * Re-queue the current job.
  * @return string
  */
 public function recreate()
 {
     $status = new Resque_Job_Status($this->payload['id']);
     $monitor = false;
     if ($status->isTracking()) {
         $monitor = true;
     }
     return self::create($this->queue, $this->payload['class'], $this->getArguments(), $monitor);
 }
Example #17
0
 /**
  * Given a token, return the job status. For mocking
  * @param string $token
  * @return mixed
  */
 protected function getJobStatus($token)
 {
     $status = new \Resque_Job_Status($token);
     return $status->get();
 }
Example #18
0
    if (!$query) {
        return new JsonResponse(['error' => "query required"], 400);
    }
    try {
        $label = new \CultuurNet\UDB3\Label($request->request->get('label'));
        $commandId = $eventLabeller->labelQuery($query, $label);
        /** @var CultureFeed_User $user */
        $user = $app['current_user'];
        $app['used_labels_memory']->rememberLabelUsed($user->id, $label);
        return new JsonResponse(['commandId' => $commandId]);
    } catch (Exception $e) {
        return new JsonResponse(['error' => $e->getMessage()], 400);
    }
});
$app->get('command/{token}', function (Request $request, Application $app, $token) {
    $status = new Resque_Job_Status($token);
    $code = $status->get();
    if (false === $code) {
        // @todo 404 not found response
    }
    $labels = array(Resque_Job_Status::STATUS_WAITING => 'waiting', Resque_Job_Status::STATUS_RUNNING => 'running', Resque_Job_Status::STATUS_COMPLETE => 'complete', Resque_Job_Status::STATUS_FAILED => 'failed');
    return new Response($labels[$code]);
});
$app->get('place/{cdbid}', function (Request $request, Application $app, $cdbid) {
    /** @var \CultuurNet\UDB3\EntityServiceInterface $service */
    $service = $app['place_service'];
    $place = $service->getEntity($cdbid);
    $response = JsonLdResponse::create()->setContent($place)->setPublic()->setClientTtl(60 * 30)->setTtl(60 * 5);
    $response->headers->set('Vary', 'Origin');
    return $response;
})->bind('place');
Example #19
0
#!/usr/bin/php
<?php 
$config = ['require_services' => ['credis', 'psr_log'], 'git_urls' => ['https://github.com/chrisboulton/php-resque.git' => 'php_resque/'], 'pear' => ['php_resque/lib/' => 'Resque'], 'example' => function () {
    Resque::setBackend('localhost:6379');
    class My_Job
    {
        public function perform()
        {
            echo $this->args['name'];
        }
    }
    $statuses = [Resque_Job_Status::STATUS_WAITING => 'STATUS_WAITING', Resque_Job_Status::STATUS_RUNNING => 'STATUS_RUNNING', Resque_Job_Status::STATUS_FAILED => 'STATUS_FAILED', Resque_Job_Status::STATUS_COMPLETE => 'STATUS_COMPLETE'];
    $args = ['name' => 'Chris'];
    $token = Resque::enqueue('default', 'My_Job', $args, true);
    echo $token . PHP_EOL;
    $status = new Resque_Job_Status($token);
    echo $statuses[$status->get()] . PHP_EOL;
    Resque::dequeue('default', ['My_Job']);
    $status = new Resque_Job_Status($token);
    echo $statuses[$status->get()] . PHP_EOL;
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
Example #20
0
<?php

if (empty($argv[1])) {
    die('Specify the ID of a job to monitor the status of.');
}
require __DIR__ . '/init.php';
date_default_timezone_set('GMT');
Resque::setBackend('127.0.0.1:6379');
$status = new Resque_Job_Status($argv[1]);
if (!$status->isTracking()) {
    die("Resque is not tracking the status of this job.\n");
}
echo "Tracking status of " . $argv[1] . ". Press [break] to stop.\n\n";
while (true) {
    fwrite(STDOUT, "Status of " . $argv[1] . " is: " . $status->get() . "\n");
    sleep(1);
}
Example #21
0
 /**
  * Get the job status.
  *
  * @param string $jobId Job Id.
  * @return int Job status.
  * @see CakeResqueShell::track()
  * @codeCoverageIgnore
  */
 public static function getJobStatus($jobId)
 {
     $JobStatus = new Resque_Job_Status($jobId);
     return $JobStatus->get();
 }
<?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());
Example #23
0
	/**
	 * Re-queue the current job.
	 */
	public function recreate()
	{
		$status = new Resque_Job_Status($id);
		$monitor = false;
		if($status->isTracking()) {
			$monitor = true;
		}

		self::create($this->queue, $this->payload->class, $this->payload->args, $monitor);
	}