Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh Project #329

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
*.swp
phpunit.xml
.idea
52 changes: 26 additions & 26 deletions bin/resque
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ foreach ($files as $file) {
if (!class_exists('Composer\Autoload\ClassLoader', false)) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}

$QUEUE = getenv('QUEUE');
if(empty($QUEUE)) {
if (empty($QUEUE)) {
die("Set QUEUE env var containing the list of queues to work.\n");
}

Expand All @@ -40,28 +40,30 @@ $REDIS_BACKEND = getenv('REDIS_BACKEND');

// A redis database number
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
if(!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB))
if (!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB)) {
Resque::setBackend($REDIS_BACKEND);
else
} else {
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}
}

$logLevel = false;
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if(!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
}
else if(!empty($VVERBOSE)) {
if (!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
} else {
if (!empty($VVERBOSE)) {
$logLevel = true;
}
}

$APP_INCLUDE = getenv('APP_INCLUDE');
if($APP_INCLUDE) {
if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
}

require_once $APP_INCLUDE;
Expand All @@ -73,35 +75,34 @@ if (!isset($logger) || !is_object($logger)) {
$logger = new Resque_Log($logLevel);
}

$BLOCKING = getenv('BLOCKING') !== FALSE;
$BLOCKING = getenv('BLOCKING') !== false;

$interval = 5;
$INTERVAL = getenv('INTERVAL');
if(!empty($INTERVAL)) {
if (!empty($INTERVAL)) {
$interval = $INTERVAL;
}

$count = 1;
$COUNT = getenv('COUNT');
if(!empty($COUNT) && $COUNT > 1) {
if (!empty($COUNT) && $COUNT > 1) {
$count = $COUNT;
}

$PREFIX = getenv('PREFIX');
if(!empty($PREFIX)) {
if (!empty($PREFIX)) {
$logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));
Resque_Redis::prefix($PREFIX);
}

if($count > 1) {
for($i = 0; $i < $count; ++$i) {
if ($count > 1) {
for ($i = 0; $i < $count; ++$i) {
$pid = Resque::fork();
if($pid === false || $pid === -1) {
if ($pid === false || $pid === -1) {
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
die();
}
// Child, start the worker
else if(!$pid) {
} elseif (!$pid) {
// Child, start the worker
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);
Expand All @@ -110,8 +111,7 @@ if($count > 1) {
break;
}
}
}
// Start a single worker
} // Start a single worker
else {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
Expand All @@ -120,7 +120,7 @@ else {
$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
die('Could not write PID information to ' . $PIDFILE);
}

$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
Expand Down
28 changes: 14 additions & 14 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<project name="php-resque" default="build">
<target name="clean">
<delete dir="${basedir}/build" />
</target>
<target name="prepare">
<mkdir dir="${basedir}/build" />
<mkdir dir="${basedir}/build/logs" />
</target>
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml
<target name="clean">
<delete dir="${basedir}/build"/>
</target>
<target name="prepare">
<mkdir dir="${basedir}/build"/>
<mkdir dir="${basedir}/build/logs"/>
</target>
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml
--coverage-clover ${basedir}/build/logs/clover.xml
--coverage-html ${basedir}/build/coverage" />
</exec>
</target>
<target name="build" depends="clean,prepare,phpunit" />
--coverage-html ${basedir}/build/coverage"/>
</exec>
</target>
<target name="build" depends="clean,prepare,phpunit"/>
</project>
87 changes: 48 additions & 39 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
{
"name": "chrisboulton/php-resque",
"type": "library",
"description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby.",
"keywords": ["job", "background", "redis", "resque"],
"homepage": "http://www.github.com/chrisboulton/php-resque/",
"license": "MIT",
"authors": [
{
"name": "Chris Boulton",
"email": "chris@bigcommerce.com"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/chrisboulton/credis"
}
],
"require": {
"php": ">=5.3.0",
"ext-pcntl": "*",
"colinmollenhour/credis": "~1.7",
"psr/log": "1.0.0"
},
"suggest": {
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker.",
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"bin": [
"bin/resque"
],
"autoload": {
"psr-0": {
"Resque": "lib"
}
}
"name": "spiritdead/php-resque",
"type": "library",
"description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby.",
"keywords": [
"job",
"background",
"redis",
"resque"
],
"homepage": "http://www.github.com/spiritdead/php-resque/",
"license": "MIT",
"authors": [
{
"name": "Chris Boulton",
"email": "chris@bigcommerce.com"
},
{
"name": "Carlos Rodriguez",
"email": "mundofreakuc@gmail.com"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/chrisboulton/credis"
}
],
"require": {
"php": ">=5.3.0",
"ext-pcntl": "*",
"colinmollenhour/credis": "~1.7",
"psr/log": "1.0.0"
},
"suggest": {
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker.",
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"bin": [
"bin/resque"
],
"autoload": {
"psr-0": {
"Resque": "lib"
}
}
}
9 changes: 5 additions & 4 deletions demo/bad_job.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

class Bad_PHP_Job
{
public function perform()
{
throw new Exception('Unable to run this job!');
}
public function perform()
{
throw new Exception('Unable to run this job!');
}
}
16 changes: 8 additions & 8 deletions demo/check_status.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
if(empty($argv[1])) {
die('Specify the ID of a job to monitor the status of.');
if (empty($argv[1])) {
die('Specify the ID of a job to monitor the status of.');
}

require __DIR__ . '/init.php';
Expand All @@ -12,12 +12,12 @@
//Resque::setBackend('redis://user:pass@a.host.name:3432/2');

$status = new Resque_Job_Status($argv[1]);
if(!$status->isTracking()) {
die("Resque is not tracking the status of this job.\n");
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);
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);
}
28 changes: 14 additions & 14 deletions demo/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
// Find and initialize Composer
// NOTE: You should NOT use this when developing against php-resque.
// The autoload code below is specifically for this demo.
$files = array(
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
);
$files = [
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../../autoload.php',
__DIR__ . '/../vendor/autoload.php'
];

$found = false;
foreach ($files as $file) {
if (file_exists($file)) {
require_once $file;
break;
}
if (file_exists($file)) {
require_once $file;
break;
}
}

if (!class_exists('Composer\Autoload\ClassLoader', false)) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}
11 changes: 6 additions & 5 deletions demo/job.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

class PHP_Job
{
public function perform()
{
public function perform()
{
fwrite(STDOUT, 'Start job! -> ');
sleep(1);
fwrite(STDOUT, 'Job ended!' . PHP_EOL);
}
sleep(1);
fwrite(STDOUT, 'Job ended!' . PHP_EOL);
}
}
9 changes: 5 additions & 4 deletions demo/long_job.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

class Long_PHP_Job
{
public function perform()
{
sleep(600);
}
public function perform()
{
sleep(600);
}
}
9 changes: 5 additions & 4 deletions demo/php_error_job.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

class PHP_Error_Job
{
public function perform()
{
callToUndefinedFunction();
}
public function perform()
{
callToUndefinedFunction();
}
}
Loading