/**
  * @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
 /**
  *
  * @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 #7
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 #8
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 #9
0
 public function ResqueStatus()
 {
     $status = new Resque_Job_Status($this->ResqueToken);
     return self::map_resque_status($status->get());
 }
Example #10
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 #11
0
        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');
$app->get('organizer/{cdbid}', function (Request $request, Application $app, $cdbid) {
Example #12
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);
     //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 #14
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();
 }
Example #15
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 #16
0
 /**
  * Return the status of the current job.
  *
  * @return int The status of the job as one of the Resque_Job_Status constants.
  */
 public function getStatus()
 {
     $status = new Resque_Job_Status($this->payload['id']);
     return $status->get();
 }
Example #17
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());
 }