Skip to content

Commit 2f725b6

Browse files
iVegaspprkut
authored andcommitted
Update resque-scheduler to use Composer autoloader
Used Composer autoloader, resque-scheduler.php script moved to the bin directory, added related changes into composer.json file.
1 parent 31079e7 commit 2f725b6

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ worker is responsible for pulling items off the schedule/delayed queue and addin
408408
them to the queue for resque. This means that for delayed or scheduled jobs to be
409409
executed, that worker needs to be running.
410410

411-
A basic "up-and-running" `resque-scheduler.php` file that sets up a
412-
running worker environment is included (`vendor/resque-scheduler.php` when
411+
A basic "up-and-running" `bin/resque-scheduler` file that sets up a
412+
running worker environment is included (`vendor/bin/resque-scheduler` when
413413
installed via composer). It accepts many of the same environment variables as
414414
the main workers for php-resque:
415415

@@ -421,14 +421,8 @@ the main workers for php-resque:
421421
* `APP_INCLUDE` - Include this file when starting (to launch your app)
422422
* `PIDFILE` - Write the PID of the worker out to this file
423423

424-
The resque-scheduler worker requires resque to function. The demo
425-
resque-scheduler.php worker allows you to supply a `RESQUE_PHP` environment
426-
variable with the path to Resque.php. If not supplied and resque is not already
427-
loaded, resque-scheduler will attempt to load it from your include path
428-
(`require_once 'Resque/Resque.php';'`)
429-
430-
It's easy to start the resque-scheduler worker using resque-scheduler.php:
431-
$ RESQUE_PHP=./lib/Resque/Resque.php php resque-scheduler.php
424+
It's easy to start the resque-scheduler worker using `bin/resque-scheduler`:
425+
$ php bin/resque-scheduler
432426

433427
## Event/Hook System
434428

resque-scheduler.php bin/resque-scheduler

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1+
#!/usr/bin/env php
12
<?php
23

3-
// Look for an environment variable with
4-
$RESQUE_PHP = getenv('RESQUE_PHP');
5-
if (!empty($RESQUE_PHP)) {
6-
require_once $RESQUE_PHP;
7-
}
8-
// Otherwise, if we have no Resque then assume it is in the include path
9-
else if (!class_exists('Resque')) {
10-
require_once 'Resque/Resque.php';
4+
// Find and initialize Composer
5+
$files = array(
6+
__DIR__ . '/../../vendor/autoload.php',
7+
__DIR__ . '/../../../autoload.php',
8+
__DIR__ . '/../../../../autoload.php',
9+
__DIR__ . '/../vendor/autoload.php',
10+
);
11+
12+
$found = false;
13+
foreach ($files as $file) {
14+
if (file_exists($file)) {
15+
require_once $file;
16+
break;
17+
}
1118
}
1219

13-
// Load resque-scheduler
14-
require_once dirname(__FILE__) . '/lib/ResqueScheduler.php';
15-
require_once dirname(__FILE__) . '/lib/ResqueScheduler/Worker.php';
20+
if (!class_exists('Composer\Autoload\ClassLoader', false)) {
21+
die(
22+
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
23+
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
24+
'php composer.phar install' . PHP_EOL
25+
);
26+
}
1627

1728
$REDIS_BACKEND = getenv('REDIS_BACKEND');
1829
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"phpunit/phpunit": "3.7.*"
4242
},
4343
"bin": [
44-
"bin/resque"
44+
"bin/resque",
45+
"bin/resque-scheduler"
4546
],
4647
"autoload": {
4748
"psr-0": {

0 commit comments

Comments
 (0)