Skip to content

Commit

Permalink
Spring cleaning
Browse files Browse the repository at this point in the history
- Replace colinmollenhour/credis with PHP redis extension
- Drop support for PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, and 8.0
- Bump psr/log to ^2.0 || ^3.0
  • Loading branch information
tspencer244 committed Nov 10, 2023
1 parent fe41c04 commit a63cb17
Show file tree
Hide file tree
Showing 55 changed files with 5,481 additions and 4,115 deletions.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2

jobs:
build:
docker:
- image: cimg/php:8.1
resource_class: small

steps:
- checkout
- run: sudo apt-get update -qq && sudo apt-get install --no-install-recommends --no-install-suggests -qq redis
- run: '{ yes "" | sudo pecl install redis; } || true'
- run: composer update
- run: composer analyse
- run: composer lint
- run: composer test
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[{*.{json,php,xml},bin/**}]
indent_size = 4
indent_style = space

[*.yml]
indent_size = 2
indent_style = space
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
vendor/
*.swp
phpunit.xml
composer.lock
/.idea/
/.php-cs-fixer.cache
/.phpunit.cache/
/composer.lock
/phpunit.xml
/vendor/
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

return (new Config())
->setFinder(Finder::create()->in(__DIR__)->name(['resque', 'resque-scheduler']))
->setRules([
'@PER' => true,
]);
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

175 changes: 87 additions & 88 deletions bin/resque
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ $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_DB)) {
Resque::setBackend($REDIS_BACKEND);
else
} else {
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}
}

$logLevel = false;
Expand All @@ -53,15 +54,14 @@ $VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if(!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
}
else if(!empty($VVERBOSE)) {
} elseif(!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");
die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
}

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

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

$interval = 5;
$INTERVAL = getenv('INTERVAL');
Expand All @@ -93,95 +93,94 @@ if(!empty($PREFIX)) {
Resque_Redis::prefix($PREFIX);
}

function cleanup_children($signal){
$GLOBALS['send_signal'] = $signal;
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");
}
// Child, start the worker
elseif(!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;
$worker->hasParent = TRUE;
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
$worker->work($interval);
break;
}
else {
$children[$pid] = 1;
while (count($children) == $count){
if (!isset($registered)) {
declare(ticks = 1);
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;
}
}
}
}
$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");
}
// Child, start the worker
elseif(!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;
$worker->hasParent = true;
fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
$worker->work($interval);
break;
} else {
$children[$pid] = 1;
while (count($children) == $count) {
if (!isset($registered)) {
declare(ticks=1);
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;
}
}
}
}
}
// Start a single worker
else {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;
$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);
}
}
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;
$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);
}
}

$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
$worker->work($interval, $BLOCKING);
}
?>
32 changes: 16 additions & 16 deletions bin/resque-scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ if (!class_exists('Composer\Autoload\ClassLoader', false)) {
$REDIS_BACKEND = getenv('REDIS_BACKEND');
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
if(!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB))
Resque::setBackend($REDIS_BACKEND);
else
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
if (empty($REDIS_BACKEND_DB)) {
Resque::setBackend($REDIS_BACKEND);
} else {
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}
}

// Set log level for resque-scheduler
Expand All @@ -40,32 +41,31 @@ $LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if(!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = ResqueScheduler_Worker::LOG_NORMAL;
}
else if(!empty($VVERBOSE)) {
$logLevel = ResqueScheduler_Worker::LOG_VERBOSE;
$logLevel = ResqueScheduler_Worker::LOG_NORMAL;
} elseif(!empty($VVERBOSE)) {
$logLevel = ResqueScheduler_Worker::LOG_VERBOSE;
}

// Check for jobs every $interval seconds
$interval = 5;
$INTERVAL = getenv('INTERVAL');
if(!empty($INTERVAL)) {
$interval = $INTERVAL;
$interval = $INTERVAL;
}

// Load the user's application if one exists
$APP_INCLUDE = getenv('APP_INCLUDE');
if($APP_INCLUDE) {
if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}
if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
}

require_once $APP_INCLUDE;
require_once $APP_INCLUDE;
}

$PREFIX = getenv('PREFIX');
if(!empty($PREFIX)) {
fwrite(STDOUT, '*** Prefix set to '.$PREFIX."\n");
fwrite(STDOUT, '*** Prefix set to ' . $PREFIX . "\n");
Resque_Redis::prefix($PREFIX);
}

Expand All @@ -74,8 +74,8 @@ $worker->logLevel = $logLevel;

$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}

fwrite(STDOUT, "*** Starting scheduler worker\n");
Expand Down
17 changes: 0 additions & 17 deletions build.xml

This file was deleted.

Loading

0 comments on commit a63cb17

Please sign in to comment.