Skip to content

Commit a5f6275

Browse files
committed
Introduce namespaces
1 parent 3bc9e6f commit a5f6275

40 files changed

+564
-381
lines changed

bin/resque

+19-19
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ $REDIS_BACKEND = getenv('REDIS_BACKEND');
4242
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
4343
if(!empty($REDIS_BACKEND)) {
4444
if (empty($REDIS_BACKEND_DB))
45-
Resque::setBackend($REDIS_BACKEND);
45+
\Resque\Resque::setBackend($REDIS_BACKEND);
4646
else
47-
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
47+
\Resque\Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
4848
}
4949

5050
$logLevel = false;
@@ -70,7 +70,7 @@ if($APP_INCLUDE) {
7070
// See if the APP_INCLUDE containes a logger object,
7171
// If none exists, fallback to internal logger
7272
if (!isset($logger) || !is_object($logger)) {
73-
$logger = new Resque_Log($logLevel);
73+
$logger = new \Resque\Logger($logLevel);
7474
}
7575

7676
$BLOCKING = getenv('BLOCKING') !== FALSE;
@@ -89,8 +89,8 @@ if(!empty($COUNT) && $COUNT > 1) {
8989

9090
$PREFIX = getenv('PREFIX');
9191
if(!empty($PREFIX)) {
92-
$logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));
93-
Resque_Redis::prefix($PREFIX);
92+
$logger->log(\Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));
93+
\Resque\Redis::prefix($PREFIX);
9494
}
9595

9696
function cleanup_children($signal){
@@ -100,19 +100,19 @@ function cleanup_children($signal){
100100
if($count > 1) {
101101
$children = array();
102102
$GLOBALS['send_signal'] = FALSE;
103-
103+
104104
$die_signals = array(SIGTERM, SIGINT, SIGQUIT);
105105
$all_signals = array_merge($die_signals, array(SIGUSR1, SIGUSR2, SIGCONT, SIGPIPE));
106-
106+
107107
for($i = 0; $i < $count; ++$i) {
108-
$pid = Resque::fork();
108+
$pid = \Resque\Resque::fork();
109109
if($pid == -1) {
110110
die("Could not fork worker ".$i."\n");
111111
}
112112
// Child, start the worker
113113
elseif(!$pid) {
114114
$queues = explode(',', $QUEUE);
115-
$worker = new Resque_Worker($queues);
115+
$worker = new \Resque\Worker\ResqueWorker($queues);
116116
$worker->logLevel = $logLevel;
117117
$worker->hasParent = TRUE;
118118
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
@@ -127,27 +127,27 @@ if($count > 1) {
127127
foreach ($all_signals as $signal) {
128128
pcntl_signal($signal, "cleanup_children");
129129
}
130-
130+
131131
$PIDFILE = getenv('PIDFILE');
132132
if ($PIDFILE) {
133133
if(file_put_contents($PIDFILE, getmypid()) === false){
134-
$logger->log(Psr\Log\LogLevel::NOTICE, 'Could not write PID information to {pidfile}', array('pidfile' => $PIDFILE));
134+
$logger->log(\Psr\Log\LogLevel::NOTICE, 'Could not write PID information to {pidfile}', array('pidfile' => $PIDFILE));
135135
die(2);
136136
}
137137
}
138-
138+
139139
$registered = TRUE;
140140
}
141-
141+
142142
if(function_exists('setproctitle')) {
143-
setproctitle('resque-' . Resque::VERSION . ": Monitoring {$count} children: [".implode(',', array_keys($children))."]");
143+
setproctitle('resque-' . \Resque\Resque::VERSION . ": Monitoring {$count} children: [".implode(',', array_keys($children))."]");
144144
}
145-
145+
146146
$childPID = pcntl_waitpid(-1, $childStatus, WNOHANG);
147147
if ($childPID != 0) {
148148
fwrite(STDOUT, "*** A child worker died: {$childPID}\n");
149149
unset($children[$childPID]);
150-
$i--;
150+
$i--;
151151
}
152152
usleep(250000);
153153
if ($GLOBALS['send_signal'] !== FALSE){
@@ -169,19 +169,19 @@ if($count > 1) {
169169
// Start a single worker
170170
else {
171171
$queues = explode(',', $QUEUE);
172-
$worker = new Resque_Worker($queues);
172+
$worker = new \Resque\Worker\ResqueWorker($queues);
173173
$worker->logLevel = $logLevel;
174174
$worker->hasParent = FALSE;
175175

176176
$PIDFILE = getenv('PIDFILE');
177177
if ($PIDFILE) {
178178
if(file_put_contents($PIDFILE, getmypid()) === false) {
179-
$logger->log(Psr\Log\LogLevel::NOTICE, 'Could not write PID information to {pidfile}', array('pidfile' => $PIDFILE));
179+
$logger->log(\Psr\Log\LogLevel::NOTICE, 'Could not write PID information to {pidfile}', array('pidfile' => $PIDFILE));
180180
die(2);
181181
}
182182
}
183183

184-
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
184+
$logger->log(\Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
185185
$worker->work($interval, $BLOCKING);
186186
}
187187
?>

bin/resque-scheduler

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ if (!class_exists('Composer\Autoload\ClassLoader', false)) {
2828
$REDIS_BACKEND = getenv('REDIS_BACKEND');
2929
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
3030
if(!empty($REDIS_BACKEND)) {
31-
if (empty($REDIS_BACKEND_DB))
32-
Resque::setBackend($REDIS_BACKEND);
31+
if (empty($REDIS_BACKEND_DB))
32+
\Resque\Resque::setBackend($REDIS_BACKEND);
3333
else
34-
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
34+
\Resque\Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
3535
}
3636

3737
// Set log level for resque-scheduler
@@ -40,10 +40,10 @@ $LOGGING = getenv('LOGGING');
4040
$VERBOSE = getenv('VERBOSE');
4141
$VVERBOSE = getenv('VVERBOSE');
4242
if(!empty($LOGGING) || !empty($VERBOSE)) {
43-
$logLevel = ResqueScheduler_Worker::LOG_NORMAL;
43+
$logLevel = \Resque\Worker\SchedulerWorker::LOG_NORMAL;
4444
}
4545
else if(!empty($VVERBOSE)) {
46-
$logLevel = ResqueScheduler_Worker::LOG_VERBOSE;
46+
$logLevel = \Resque\Worker\SchedulerWorker::LOG_VERBOSE;
4747
}
4848

4949
// Check for jobs every $interval seconds
@@ -66,10 +66,10 @@ if($APP_INCLUDE) {
6666
$PREFIX = getenv('PREFIX');
6767
if(!empty($PREFIX)) {
6868
fwrite(STDOUT, '*** Prefix set to '.$PREFIX."\n");
69-
Resque_Redis::prefix($PREFIX);
69+
\Resque\Redis::prefix($PREFIX);
7070
}
7171

72-
$worker = new ResqueScheduler_Worker();
72+
$worker = new \Resque\Worker\SchedulerWorker();
7373
$worker->logLevel = $logLevel;
7474

7575
$PIDFILE = getenv('PIDFILE');

composer.json

+13-9
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@
4545
"bin/resque-scheduler"
4646
],
4747
"autoload": {
48-
"psr-0": {
49-
"Resque": "lib",
50-
"ResqueScheduler": "lib"
48+
"psr-4": {
49+
"Resque\\": "lib"
5150
}
52-
},
53-
"extra": {
54-
"branch-alias": {
55-
"dev-master": "1.0-dev"
56-
}
57-
}
51+
},
52+
"autoload-dev": {
53+
"psr-4": {
54+
"Resque\\Tests\\": "test/Resque/Tests"
55+
}
56+
},
57+
"extra": {
58+
"branch-alias": {
59+
"dev-master": "1.0-dev"
60+
}
61+
}
5862
}

demo/bad_job.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ class Bad_PHP_Job
33
{
44
public function perform()
55
{
6-
throw new Exception('Unable to run this job!');
6+
throw new \Exception('Unable to run this job!');
77
}
8-
}
8+
}

demo/check_status.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
require __DIR__ . '/init.php';
77

88
date_default_timezone_set('GMT');
9-
Resque::setBackend('127.0.0.1:6379');
9+
\Resque\Resque::setBackend('127.0.0.1:6379');
1010
// You can also use a DSN-style format:
11-
//Resque::setBackend('redis://user:[email protected]:6379');
12-
//Resque::setBackend('redis://user:[email protected]:3432/2');
11+
//\Resque\Resque::setBackend('redis://user:[email protected]:6379');
12+
//\Resque\Resque::setBackend('redis://user:[email protected]:3432/2');
1313

14-
$status = new Resque_Job_Status($argv[1]);
14+
$status = new \Resque\Job\Status($argv[1]);
1515
if(!$status->isTracking()) {
1616
die("Resque is not tracking the status of this job.\n");
1717
}
@@ -20,4 +20,4 @@
2020
while(true) {
2121
fwrite(STDOUT, "Status of ".$argv[1]." is: ".$status->get()."\n");
2222
sleep(1);
23-
}
23+
}

demo/queue.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require __DIR__ . '/init.php';
77
date_default_timezone_set('GMT');
8-
Resque::setBackend('127.0.0.1:6379');
8+
\Resque\Resque::setBackend('127.0.0.1:6379');
99

1010
// You can also use a DSN-style format:
1111
//Resque::setBackend('redis://user:[email protected]:6379');
@@ -18,9 +18,9 @@
1818
),
1919
);
2020
if (empty($argv[2])) {
21-
$jobId = Resque::enqueue('default', $argv[1], $args, true);
21+
$jobId = \Resque\Resque::enqueue('default', $argv[1], $args, true);
2222
} else {
23-
$jobId = Resque::enqueue($argv[1], $argv[2], $args, true);
23+
$jobId = \Resque\Resque::enqueue($argv[1], $argv[2], $args, true);
2424
}
2525

2626
echo "Queued job ".$jobId."\n\n";

lib/Resque/Event.php renamed to lib/Event.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
namespace Resque;
4+
35
/**
46
* Resque event/plugin system class
57
*
68
* @package Resque/Event
79
* @author Chris Boulton <[email protected]>
810
* @license http://www.opensource.org/licenses/mit-license.php
911
*/
10-
class Resque_Event
12+
class Event
1113
{
1214
/**
1315
* @var array Array containing all registered callbacks, indexked by event name.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
namespace Resque\Exceptions;
4+
5+
use \RuntimeException;
6+
37
/**
48
* Runtime exception class for a job that does not exit cleanly.
59
*
610
* @package Resque/Job
711
* @author Chris Boulton <[email protected]>
812
* @license http://www.opensource.org/licenses/mit-license.php
913
*/
10-
class Resque_Job_DirtyExitException extends RuntimeException
14+
class DirtyExitException extends RuntimeException
1115
{
1216
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
namespace Resque\Exceptions;
4+
5+
use \Exception as CoreException;
6+
37
/**
48
* Exception to be thrown if while enqueuing a job it should not be created.
59
*
610
* @package Resque/Job
711
* @author Chris Boulton <[email protected]>
812
* @license http://www.opensource.org/licenses/mit-license.php
913
*/
10-
class Resque_Job_DontCreate extends Exception
14+
class DoNotCreateException extends CoreException
1115
{
1216
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
namespace Resque\Exceptions;
4+
5+
use \Exception as CoreException;
6+
37
/**
48
* Exception to be thrown if a job should not be performed/run.
59
*
610
* @package Resque/Job
711
* @author Chris Boulton <[email protected]>
812
* @license http://www.opensource.org/licenses/mit-license.php
913
*/
10-
class Resque_Job_DontPerform extends Exception
14+
class DoNotPerformException extends CoreException
1115
{
1216
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
namespace Resque\Exceptions;
4+
5+
use \Exception as CoreException;
6+
37
/**
48
* Resque exception.
59
*
610
* @package Resque
711
* @author Chris Boulton <[email protected]>
812
* @license http://www.opensource.org/licenses/mit-license.php
913
*/
10-
class Resque_Exception extends Exception
14+
class Exception extends CoreException
1115
{
1216
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Resque\Exceptions;
4+
5+
/**
6+
* Exception thrown whenever an invalid timestamp has been passed to a job.
7+
*
8+
* @package ResqueScheduler
9+
* @author Chris Boulton <[email protected]>
10+
* @copyright (c) 2012 Chris Boulton
11+
* @license http://www.opensource.org/licenses/mit-license.php
12+
*/
13+
class InvalidTimestampException extends Exception
14+
{
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
namespace Resque\Exceptions;
4+
35
/**
46
* Redis related exceptions
57
*
68
* @package Resque
79
* @author Chris Boulton <[email protected]>
810
* @license http://www.opensource.org/licenses/mit-license.php
911
*/
10-
class Resque_RedisException extends Resque_Exception
12+
class RedisException extends Exception
1113
{
1214
}

lib/Resque/Failure/Interface.php renamed to lib/Failure/FailureInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?php
22

3+
namespace Resque\Failure;
4+
35
/**
46
* Interface that all failure backends should implement.
57
*
68
* @package Resque/Failure
79
* @author Chris Boulton <[email protected]>
810
* @license http://www.opensource.org/licenses/mit-license.php
911
*/
10-
interface Resque_Failure_Interface
12+
interface FailureInterface
1113
{
1214
/**
1315
* Initialize a failed job class and save it (where appropriate).
1416
*
1517
* @param object $payload Object containing details of the failed job.
1618
* @param object $exception Instance of the exception that was thrown by the failed job.
17-
* @param object $worker Instance of Resque_Worker that received the job.
19+
* @param object $worker Instance of \Resque\Worker\ResqueWorker that received the job.
1820
* @param string $queue The name of the queue the job was fetched from.
1921
*/
2022
public function __construct($payload, $exception, $worker, $queue);

0 commit comments

Comments
 (0)