From 0f6c39b7b5afd036b80c3d610de73733cc4f886e Mon Sep 17 00:00:00 2001 From: Thomas Spencer Date: Mon, 13 Nov 2023 17:45:53 +0800 Subject: [PATCH] Revert the bin script (#9) --- .php-cs-fixer.dist.php | 2 +- bin/resque | 83 ++++++------------------------------------ bin/resque-scheduler | 82 ----------------------------------------- composer.json | 6 +-- phpstan-baseline.neon | 70 +++++------------------------------ phpstan.dist.neon | 1 - 6 files changed, 24 insertions(+), 220 deletions(-) delete mode 100644 bin/resque-scheduler diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index a0dd131..3074509 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -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, ]); diff --git a/bin/resque b/bin/resque index e22f244..89679b5 100755 --- a/bin/resque +++ b/bin/resque @@ -2,8 +2,6 @@ 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; - } - } } } } @@ -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)); diff --git a/bin/resque-scheduler b/bin/resque-scheduler deleted file mode 100644 index 6942bab..0000000 --- a/bin/resque-scheduler +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env php -logLevel = $logLevel; - -$PIDFILE = getenv('PIDFILE'); -if ($PIDFILE) { - file_put_contents($PIDFILE, getmypid()) or - die('Could not write PID information to ' . $PIDFILE); -} - -fwrite(STDOUT, "*** Starting scheduler worker\n"); -$worker->work($interval); diff --git a/composer.json b/composer.json index f3477a5..ef300cb 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6ee7db0..b145e53 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 - @@ -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\\\\|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\\\\|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 @@ -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 diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 05ff10c..15b546d 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -4,5 +4,4 @@ parameters: level: 9 paths: - bin/resque - - bin/resque-scheduler - lib