Skip to content

Commit

Permalink
Revert the bin script (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tspencer244 authored Nov 13, 2023
1 parent 1a7c35e commit 0f6c39b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 220 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpCsFixer\Finder;

return (new Config())
->setFinder(Finder::create()->in(__DIR__)->name(['resque', 'resque-scheduler']))
->setFinder(Finder::create()->in(__DIR__)->name(['resque']))
->setRules([
'@PER' => true,
]);
83 changes: 11 additions & 72 deletions bin/resque
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<?php

// Find and initialize Composer
use Psr\Log\LoggerInterface;

$files = array(
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
Expand All @@ -22,8 +20,8 @@ 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
);
}

Expand Down Expand Up @@ -69,9 +67,9 @@ if($APP_INCLUDE) {
require_once $APP_INCLUDE;
}

// See if the APP_INCLUDE contains a logger object,
// See if the APP_INCLUDE containes a logger object,
// If none exists, fallback to internal logger
if (!isset($logger) || !($logger instanceof LoggerInterface)) {
if (!isset($logger) || !is_object($logger)) {
$logger = new Resque_Log($logLevel);
}

Expand All @@ -95,77 +93,21 @@ if(!empty($PREFIX)) {
Resque_Redis::prefix($PREFIX);
}

function cleanup_children($signal)
{
$GLOBALS['send_signal'] = $signal;
}

if($count > 1) {
$children = array();
$GLOBALS['send_signal'] = false;

$die_signals = array(SIGTERM, SIGINT, SIGQUIT);
$all_signals = array_merge($die_signals, array(SIGUSR1, SIGUSR2, SIGCONT, SIGPIPE));

for($i = 0; $i < $count; ++$i) {
$pid = Resque::fork();
if($pid == -1) {
die("Could not fork worker " . $i . "\n");
if($pid === false || $pid === -1) {
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
die();
}
// Child, start the worker
elseif(!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);
$worker->hasParent = true;
fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
$worker->work($interval);
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
$worker->work($interval, $BLOCKING);
break;
} else {
$children[$pid] = 1;
while (count($children) == $count) {
if (!isset($registered)) {
pcntl_async_signals(true);

foreach ($all_signals as $signal) {
pcntl_signal($signal, "cleanup_children");
}

$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
if(file_put_contents($PIDFILE, getmypid()) === false) {
$logger->log(Psr\Log\LogLevel::NOTICE, 'Could not write PID information to {pidfile}', array('pidfile' => $PIDFILE));
die(2);
}
}

$registered = true;
}

if(function_exists('setproctitle')) {
setproctitle('resque-' . Resque::VERSION . ": Monitoring {$count} children: [" . implode(',', array_keys($children)) . "]");
}

$childPID = pcntl_waitpid(-1, $childStatus, WNOHANG);
if ($childPID != 0) {
fwrite(STDOUT, "*** A child worker died: {$childPID}\n");
unset($children[$childPID]);
$i--;
}
usleep(250000);
if ($GLOBALS['send_signal'] !== false) {
foreach ($children as $k => $v) {
posix_kill($k, $GLOBALS['send_signal']);
if (in_array($GLOBALS['send_signal'], $die_signals)) {
pcntl_waitpid($k, $childStatus);
}
}
if (in_array($GLOBALS['send_signal'], $die_signals)) {
exit;
}
$GLOBALS['send_signal'] = false;
}
}
}
}
}
Expand All @@ -174,14 +116,11 @@ else {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);
$worker->hasParent = false;

$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
if(file_put_contents($PIDFILE, getmypid()) === false) {
$logger->log(Psr\Log\LogLevel::NOTICE, 'Could not write PID information to {pidfile}', array('pidfile' => $PIDFILE));
die(2);
}
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}

$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
Expand Down
82 changes: 0 additions & 82 deletions bin/resque-scheduler

This file was deleted.

6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
"phpunit/phpunit": "^10.4"
},
"bin": [
"bin/resque",
"bin/resque-scheduler"
"bin/resque"
],
"autoload": {
"psr-0": {
"Resque": "lib/",
"ResqueScheduler": "lib/"
"Resque": "lib/"
}
},
"autoload-dev": {
Expand Down
70 changes: 10 additions & 60 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Resque_Worker\\:\\:\\$hasParent\\.$#"
count: 2
path: bin/resque

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 2
message: "#^Call to an undefined method object\\:\\:log\\(\\)\\.$#"
count: 4
path: bin/resque

-
Expand All @@ -16,27 +11,27 @@ parameters:
path: bin/resque

-
message: "#^Function cleanup_children\\(\\) has no return type specified\\.$#"
message: "#^Only booleans are allowed in a negated boolean, int\\<min, \\-2\\>\\|int\\<0, max\\> given\\.$#"
count: 1
path: bin/resque

-
message: "#^Function cleanup_children\\(\\) has parameter \\$signal with no type specified\\.$#"
count: 1
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 2
path: bin/resque

-
message: "#^Only booleans are allowed in a negated boolean, int\\<min, \\-2\\>\\|int\\<0, max\\> given\\.$#"
message: "#^Only booleans are allowed in \\|\\|, int\\<0, max\\>\\|false given on the left side\\.$#"
count: 1
path: bin/resque

-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 3
message: "#^Parameter \\#1 \\$interval of method Resque_Worker\\:\\:work\\(\\) expects int, int\\|string given\\.$#"
count: 2
path: bin/resque

-
message: "#^Parameter \\#1 \\$interval of method Resque_Worker\\:\\:work\\(\\) expects int, int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$logger of method Resque_Worker\\:\\:setLogger\\(\\) expects Psr\\\\Log\\\\LoggerInterface, object given\\.$#"
count: 2
path: bin/resque

Expand All @@ -46,55 +41,10 @@ parameters:
path: bin/resque

-
message: "#^Strict comparison using \\!\\=\\= between false and false will always evaluate to false\\.$#"
message: "#^Strict comparison using \\=\\=\\= between int and false will always evaluate to false\\.$#"
count: 1
path: bin/resque

-
message: "#^Access to constant LOG_NORMAL on an unknown class ResqueScheduler_Worker\\.$#"
count: 1
path: bin/resque-scheduler

-
message: "#^Access to constant LOG_VERBOSE on an unknown class ResqueScheduler_Worker\\.$#"
count: 1
path: bin/resque-scheduler

-
message: "#^Access to property \\$logLevel on an unknown class ResqueScheduler_Worker\\.$#"
count: 2
path: bin/resque-scheduler

-
message: "#^Call to method work\\(\\) on an unknown class ResqueScheduler_Worker\\.$#"
count: 1
path: bin/resque-scheduler

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 7
path: bin/resque-scheduler

-
message: "#^Instantiated class ResqueScheduler_Worker not found\\.$#"
count: 1
path: bin/resque-scheduler

-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 2
path: bin/resque-scheduler

-
message: "#^Only booleans are allowed in \\|\\|, int\\<0, max\\>\\|false given on the left side\\.$#"
count: 1
path: bin/resque-scheduler

-
message: "#^Parameter \\#2 \\$database of static method Resque\\:\\:setBackend\\(\\) expects int, string given\\.$#"
count: 1
path: bin/resque-scheduler

-
message: "#^Call to an undefined method Resque_Redis\\:\\:blpop\\(\\)\\.$#"
count: 1
Expand Down
1 change: 0 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ parameters:
level: 9
paths:
- bin/resque
- bin/resque-scheduler
- lib

0 comments on commit 0f6c39b

Please sign in to comment.