mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-21 16:01:53 +00:00
Global reformat
This commit is contained in:
parent
14c0e26559
commit
51fda513f4
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
if(empty($argv[1])) {
|
||||
if (empty($argv[1])) {
|
||||
die('Specify the ID of a job to monitor the status of.');
|
||||
}
|
||||
|
||||
@ -12,12 +12,12 @@ Resque::setBackend('127.0.0.1:6379');
|
||||
//Resque::setBackend('redis://user:pass@a.host.name:3432/2');
|
||||
|
||||
$status = new Resque_Job_Status($argv[1]);
|
||||
if(!$status->isTracking()) {
|
||||
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");
|
||||
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);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
class PHP_Job
|
||||
{
|
||||
public function perform()
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Long_PHP_Job
|
||||
{
|
||||
public function perform()
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
class PHP_Error_Job
|
||||
{
|
||||
public function perform()
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
if(empty($argv[1])) {
|
||||
if (empty($argv[1])) {
|
||||
die('Specify the name of a job to add. e.g, php queue.php PHP_Job');
|
||||
}
|
||||
|
||||
@ -23,4 +23,4 @@ if (empty($argv[2])) {
|
||||
$jobId = Resque::enqueue($argv[1], $argv[2], $args, true);
|
||||
}
|
||||
|
||||
echo "Queued job ".$jobId."\n\n";
|
||||
echo "Queued job " . $jobId . "\n\n";
|
||||
|
@ -8,7 +8,7 @@ Resque_Event::listen('beforePerform', array('My_Resque_Plugin', 'beforePerform')
|
||||
Resque_Event::listen('afterPerform', array('My_Resque_Plugin', 'afterPerform'));
|
||||
Resque_Event::listen('onFailure', array('My_Resque_Plugin', 'onFailure'));
|
||||
|
||||
class My_Resque_Plugin
|
||||
class Sample_Resque_Plugin
|
||||
{
|
||||
public static function afterEnqueue($class, $arguments)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ class Resque_Job
|
||||
$id = Resque::generateJobId();
|
||||
}
|
||||
|
||||
if($args !== null && !is_array($args)) {
|
||||
if ($args !== null && !is_array($args)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Supplied $args must be an array.'
|
||||
);
|
||||
@ -77,7 +77,7 @@ class Resque_Job
|
||||
'queue_time' => microtime(true),
|
||||
));
|
||||
|
||||
if($monitor) {
|
||||
if ($monitor) {
|
||||
Resque_Job_Status::create($id);
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ class Resque_Job
|
||||
public static function reserve($queue)
|
||||
{
|
||||
$payload = Resque::pop($queue);
|
||||
if(!is_array($payload)) {
|
||||
if (!is_array($payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ class Resque_Job
|
||||
public static function reserveBlocking(array $queues, $timeout = null)
|
||||
{
|
||||
$item = Resque::blpop($queues, $timeout);
|
||||
if(!is_array($item)) {
|
||||
if (!is_array($item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ class Resque_Job
|
||||
*/
|
||||
public function updateStatus($status)
|
||||
{
|
||||
if(empty($this->payload['id'])) {
|
||||
if (empty($this->payload['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -188,20 +188,19 @@ class Resque_Job
|
||||
Resque_Event::trigger('beforePerform', $this);
|
||||
|
||||
$instance = $this->getInstance();
|
||||
if(method_exists($instance, 'setUp')) {
|
||||
if (method_exists($instance, 'setUp')) {
|
||||
$instance->setUp();
|
||||
}
|
||||
|
||||
$instance->perform();
|
||||
|
||||
if(method_exists($instance, 'tearDown')) {
|
||||
if (method_exists($instance, 'tearDown')) {
|
||||
$instance->tearDown();
|
||||
}
|
||||
|
||||
Resque_Event::trigger('afterPerform', $this);
|
||||
}
|
||||
// beforePerform/setUp have said don't perform this job. Return.
|
||||
catch(Resque_Job_DontPerform $e) {
|
||||
} // beforePerform/setUp have said don't perform this job. Return.
|
||||
catch (Resque_Job_DontPerform $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -239,7 +238,7 @@ class Resque_Job
|
||||
{
|
||||
$status = new Resque_Job_Status($this->payload['id']);
|
||||
$monitor = false;
|
||||
if($status->isTracking()) {
|
||||
if ($status->isTracking()) {
|
||||
$monitor = true;
|
||||
}
|
||||
|
||||
@ -254,13 +253,13 @@ class Resque_Job
|
||||
public function __toString()
|
||||
{
|
||||
$name = array(
|
||||
'Job{' . $this->queue .'}'
|
||||
'Job{' . $this->queue . '}'
|
||||
);
|
||||
if(!empty($this->payload['id'])) {
|
||||
if (!empty($this->payload['id'])) {
|
||||
$name[] = 'ID: ' . $this->payload['id'];
|
||||
}
|
||||
$name[] = $this->payload['class'];
|
||||
if(!empty($this->payload['args'])) {
|
||||
if (!empty($this->payload['args'])) {
|
||||
$name[] = json_encode($this->payload['args']);
|
||||
}
|
||||
return '(' . implode(' | ', $name) . ')';
|
||||
|
@ -239,8 +239,7 @@ class Resque_Redis
|
||||
foreach ($args[0] AS $i => $v) {
|
||||
$args[0][$i] = self::$defaultNamespace . $v;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$args[0] = self::$defaultNamespace . $args[0];
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ use Psr\Log\LoggerInterface;
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Worker
|
||||
{
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
{
|
||||
$num = 3;
|
||||
// Register a few workers
|
||||
for($i = 0; $i < $num; ++$i) {
|
||||
for ($i = 0; $i < $num; ++$i) {
|
||||
$worker = new Resque_Worker('queue_' . $i);
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->registerWorker();
|
||||
@ -180,7 +180,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
|
||||
$job = $worker->job();
|
||||
$this->assertEquals('jobs', $job['queue']);
|
||||
if(!isset($job['run_at'])) {
|
||||
if (!isset($job['run_at'])) {
|
||||
$this->fail('Job does not have run_at time');
|
||||
}
|
||||
$this->assertEquals($payload, $job['payload']);
|
||||
@ -211,12 +211,12 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
// Register some bad workers
|
||||
$worker = new Resque_Worker('jobs');
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->setId($workerId[0].':1:jobs');
|
||||
$worker->setId($workerId[0] . ':1:jobs');
|
||||
$worker->registerWorker();
|
||||
|
||||
$worker = new Resque_Worker(array('high', 'low'));
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->setId($workerId[0].':2:high,low');
|
||||
$worker->setId($workerId[0] . ':2:high,low');
|
||||
$worker->registerWorker();
|
||||
|
||||
$this->assertEquals(3, count(Resque_Worker::all()));
|
||||
@ -233,7 +233,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
$worker = new Resque_Worker('jobs');
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$workerId = explode(':', $worker);
|
||||
$worker->setId($workerId[0].':1:jobs');
|
||||
$worker->setId($workerId[0] . ':1:jobs');
|
||||
$worker->registerWorker();
|
||||
|
||||
// Register some other false workers
|
||||
@ -282,11 +282,10 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
Resque::enqueue('jobs', 'Test_Job_2');
|
||||
|
||||
$i = 1;
|
||||
while($job = $worker->reserve(true, 2))
|
||||
{
|
||||
while ($job = $worker->reserve(true, 2)) {
|
||||
$this->assertEquals('Test_Job_' . $i, $job->payload['class']);
|
||||
|
||||
if($i == 2) {
|
||||
if ($i == 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user