Global reformat

This commit is contained in:
Daniel Mason 2018-05-25 21:03:48 +12:00
parent 14c0e26559
commit 51fda513f4
11 changed files with 532 additions and 533 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
if(empty($argv[1])) { if (empty($argv[1])) {
die('Specify the ID of a job to monitor the status of.'); 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'); //Resque::setBackend('redis://user:pass@a.host.name:3432/2');
$status = new Resque_Job_Status($argv[1]); $status = new Resque_Job_Status($argv[1]);
if(!$status->isTracking()) { if (!$status->isTracking()) {
die("Resque is not tracking the status of this job.\n"); die("Resque is not tracking the status of this job.\n");
} }
echo "Tracking status of ".$argv[1].". Press [break] to stop.\n\n"; echo "Tracking status of " . $argv[1] . ". Press [break] to stop.\n\n";
while(true) { while (true) {
fwrite(STDOUT, "Status of ".$argv[1]." is: ".$status->get()."\n"); fwrite(STDOUT, "Status of " . $argv[1] . " is: " . $status->get() . "\n");
sleep(1); sleep(1);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
class PHP_Job class PHP_Job
{ {
public function perform() public function perform()

View File

@ -1,4 +1,5 @@
<?php <?php
class Long_PHP_Job class Long_PHP_Job
{ {
public function perform() public function perform()

View File

@ -1,4 +1,5 @@
<?php <?php
class PHP_Error_Job class PHP_Error_Job
{ {
public function perform() public function perform()

View File

@ -1,5 +1,5 @@
<?php <?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'); 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); $jobId = Resque::enqueue($argv[1], $argv[2], $args, true);
} }
echo "Queued job ".$jobId."\n\n"; echo "Queued job " . $jobId . "\n\n";

View File

@ -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('afterPerform', array('My_Resque_Plugin', 'afterPerform'));
Resque_Event::listen('onFailure', array('My_Resque_Plugin', 'onFailure')); Resque_Event::listen('onFailure', array('My_Resque_Plugin', 'onFailure'));
class My_Resque_Plugin class Sample_Resque_Plugin
{ {
public static function afterEnqueue($class, $arguments) public static function afterEnqueue($class, $arguments)
{ {

View File

@ -65,7 +65,7 @@ class Resque_Job
$id = Resque::generateJobId(); $id = Resque::generateJobId();
} }
if($args !== null && !is_array($args)) { if ($args !== null && !is_array($args)) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
'Supplied $args must be an array.' 'Supplied $args must be an array.'
); );
@ -77,7 +77,7 @@ class Resque_Job
'queue_time' => microtime(true), 'queue_time' => microtime(true),
)); ));
if($monitor) { if ($monitor) {
Resque_Job_Status::create($id); Resque_Job_Status::create($id);
} }
@ -94,7 +94,7 @@ class Resque_Job
public static function reserve($queue) public static function reserve($queue)
{ {
$payload = Resque::pop($queue); $payload = Resque::pop($queue);
if(!is_array($payload)) { if (!is_array($payload)) {
return false; return false;
} }
@ -112,7 +112,7 @@ class Resque_Job
public static function reserveBlocking(array $queues, $timeout = null) public static function reserveBlocking(array $queues, $timeout = null)
{ {
$item = Resque::blpop($queues, $timeout); $item = Resque::blpop($queues, $timeout);
if(!is_array($item)) { if (!is_array($item)) {
return false; return false;
} }
@ -126,7 +126,7 @@ class Resque_Job
*/ */
public function updateStatus($status) public function updateStatus($status)
{ {
if(empty($this->payload['id'])) { if (empty($this->payload['id'])) {
return; return;
} }
@ -188,20 +188,19 @@ class Resque_Job
Resque_Event::trigger('beforePerform', $this); Resque_Event::trigger('beforePerform', $this);
$instance = $this->getInstance(); $instance = $this->getInstance();
if(method_exists($instance, 'setUp')) { if (method_exists($instance, 'setUp')) {
$instance->setUp(); $instance->setUp();
} }
$instance->perform(); $instance->perform();
if(method_exists($instance, 'tearDown')) { if (method_exists($instance, 'tearDown')) {
$instance->tearDown(); $instance->tearDown();
} }
Resque_Event::trigger('afterPerform', $this); Resque_Event::trigger('afterPerform', $this);
} } // beforePerform/setUp have said don't perform this job. Return.
// beforePerform/setUp have said don't perform this job. Return. catch (Resque_Job_DontPerform $e) {
catch(Resque_Job_DontPerform $e) {
return false; return false;
} }
@ -239,7 +238,7 @@ class Resque_Job
{ {
$status = new Resque_Job_Status($this->payload['id']); $status = new Resque_Job_Status($this->payload['id']);
$monitor = false; $monitor = false;
if($status->isTracking()) { if ($status->isTracking()) {
$monitor = true; $monitor = true;
} }
@ -254,13 +253,13 @@ class Resque_Job
public function __toString() public function __toString()
{ {
$name = array( $name = array(
'Job{' . $this->queue .'}' 'Job{' . $this->queue . '}'
); );
if(!empty($this->payload['id'])) { if (!empty($this->payload['id'])) {
$name[] = 'ID: ' . $this->payload['id']; $name[] = 'ID: ' . $this->payload['id'];
} }
$name[] = $this->payload['class']; $name[] = $this->payload['class'];
if(!empty($this->payload['args'])) { if (!empty($this->payload['args'])) {
$name[] = json_encode($this->payload['args']); $name[] = json_encode($this->payload['args']);
} }
return '(' . implode(' | ', $name) . ')'; return '(' . implode(' | ', $name) . ')';

View File

@ -239,8 +239,7 @@ class Resque_Redis
foreach ($args[0] AS $i => $v) { foreach ($args[0] AS $i => $v) {
$args[0][$i] = self::$defaultNamespace . $v; $args[0][$i] = self::$defaultNamespace . $v;
} }
} } else {
else {
$args[0] = self::$defaultNamespace . $args[0]; $args[0] = self::$defaultNamespace . $args[0];
} }
} }

View File

@ -11,7 +11,6 @@ use Psr\Log\LoggerInterface;
* @author Chris Boulton <chris@bigcommerce.com> * @author Chris Boulton <chris@bigcommerce.com>
* @license http://www.opensource.org/licenses/mit-license.php * @license http://www.opensource.org/licenses/mit-license.php
*/ */
class Resque_Worker class Resque_Worker
{ {
/** /**

View File

@ -24,7 +24,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
{ {
$num = 3; $num = 3;
// Register a few workers // Register a few workers
for($i = 0; $i < $num; ++$i) { for ($i = 0; $i < $num; ++$i) {
$worker = new Resque_Worker('queue_' . $i); $worker = new Resque_Worker('queue_' . $i);
$worker->setLogger(new Resque_Log()); $worker->setLogger(new Resque_Log());
$worker->registerWorker(); $worker->registerWorker();
@ -180,7 +180,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
$job = $worker->job(); $job = $worker->job();
$this->assertEquals('jobs', $job['queue']); $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->fail('Job does not have run_at time');
} }
$this->assertEquals($payload, $job['payload']); $this->assertEquals($payload, $job['payload']);
@ -211,12 +211,12 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
// Register some bad workers // Register some bad workers
$worker = new Resque_Worker('jobs'); $worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log()); $worker->setLogger(new Resque_Log());
$worker->setId($workerId[0].':1:jobs'); $worker->setId($workerId[0] . ':1:jobs');
$worker->registerWorker(); $worker->registerWorker();
$worker = new Resque_Worker(array('high', 'low')); $worker = new Resque_Worker(array('high', 'low'));
$worker->setLogger(new Resque_Log()); $worker->setLogger(new Resque_Log());
$worker->setId($workerId[0].':2:high,low'); $worker->setId($workerId[0] . ':2:high,low');
$worker->registerWorker(); $worker->registerWorker();
$this->assertEquals(3, count(Resque_Worker::all())); $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 = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log()); $worker->setLogger(new Resque_Log());
$workerId = explode(':', $worker); $workerId = explode(':', $worker);
$worker->setId($workerId[0].':1:jobs'); $worker->setId($workerId[0] . ':1:jobs');
$worker->registerWorker(); $worker->registerWorker();
// Register some other false workers // Register some other false workers
@ -282,11 +282,10 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
Resque::enqueue('jobs', 'Test_Job_2'); Resque::enqueue('jobs', 'Test_Job_2');
$i = 1; $i = 1;
while($job = $worker->reserve(true, 2)) while ($job = $worker->reserve(true, 2)) {
{
$this->assertEquals('Test_Job_' . $i, $job->payload['class']); $this->assertEquals('Test_Job_' . $i, $job->payload['class']);
if($i == 2) { if ($i == 2) {
break; break;
} }