Skip to content

Commit

Permalink
Fix PCNTL signals and set worker logger (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tspencer244 authored Nov 13, 2023
1 parent bc5ea60 commit 464ab32
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 52 deletions.
10 changes: 6 additions & 4 deletions bin/resque
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<?php

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

$files = array(
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
Expand Down Expand Up @@ -67,9 +69,9 @@ if($APP_INCLUDE) {
require_once $APP_INCLUDE;
}

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

Expand Down Expand Up @@ -114,7 +116,7 @@ if($count > 1) {
elseif(!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;
$worker->setLogger($logger);
$worker->hasParent = true;
fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
$worker->work($interval);
Expand Down Expand Up @@ -171,7 +173,7 @@ if($count > 1) {
else {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel;
$worker->setLogger($logger);
$worker->hasParent = false;

$PIDFILE = getenv('PIDFILE');
Expand Down
4 changes: 0 additions & 4 deletions lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ public static function redis()
*/
public static function fork()
{
if(!function_exists('pcntl_fork')) {
return false;
}

// Close the connection to Redis before forking.
// This is a workaround for issues phpredis has.
self::$redis = null;
Expand Down
9 changes: 4 additions & 5 deletions lib/Resque/Worker.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Psr\Log\LoggerInterface;

/**
* Resque worker that handles checking queues for jobs, fetching them
* off the queues, running them and handling the result.
Expand All @@ -16,7 +18,7 @@ class Resque_Worker
private static $processPrefix = 'resque';

/**
* @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface
* @var LoggerInterface Logging object that implements the PSR-3 LoggerInterface
*/
public $logger;

Expand Down Expand Up @@ -391,10 +393,7 @@ private function updateProcLine($status)
*/
private function registerSigHandlers()
{
if(!function_exists('pcntl_signal')) {
return;
}

pcntl_async_signals(true);
pcntl_signal(SIGTERM, array($this, 'shutDownNow'));
pcntl_signal(SIGINT, array($this, 'shutDownNow'));
pcntl_signal(SIGQUIT, array($this, 'shutdown'));
Expand Down
5 changes: 1 addition & 4 deletions lib/ResqueScheduler/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ public function log($message)
*/
private function registerSigHandlers()
{
if(!function_exists('pcntl_signal')) {
return;
}

pcntl_async_signals(true);
pcntl_signal(SIGTERM, array($this, 'shutdown'));
pcntl_signal(SIGINT, array($this, 'shutdown'));
pcntl_signal(SIGQUIT, array($this, 'shutdown'));
Expand Down
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Resque_Worker\\:\\:\\$logLevel\\.$#"
count: 2
path: bin/resque

-
message: "#^Call to an undefined method object\\:\\:log\\(\\)\\.$#"
count: 4
path: bin/resque

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 2
Expand Down Expand Up @@ -195,11 +185,6 @@ parameters:
count: 1
path: lib/Resque.php

-
message: "#^Method Resque\\:\\:fork\\(\\) should return int but returns false\\.$#"
count: 1
path: lib/Resque.php

-
message: "#^Method Resque\\:\\:generateJobId\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -790,11 +775,6 @@ parameters:
count: 1
path: lib/Resque/Worker.php

-
message: "#^Call to method log\\(\\) on an unknown class LoggerInterface\\.$#"
count: 23
path: lib/Resque/Worker.php

-
message: "#^Cannot access property \\$queue on object\\|true\\.$#"
count: 1
Expand Down Expand Up @@ -1020,21 +1000,6 @@ parameters:
count: 1
path: lib/Resque/Worker.php

-
message: "#^Property Resque_Worker\\:\\:\\$logger \\(LoggerInterface\\) does not accept Psr\\\\Log\\\\LoggerInterface\\.$#"
count: 1
path: lib/Resque/Worker.php

-
message: "#^Property Resque_Worker\\:\\:\\$logger \\(LoggerInterface\\) does not accept Resque_Log\\.$#"
count: 1
path: lib/Resque/Worker.php

-
message: "#^Property Resque_Worker\\:\\:\\$logger has unknown class LoggerInterface as its type\\.$#"
count: 1
path: lib/Resque/Worker.php

-
message: "#^Property Resque_Worker\\:\\:\\$queues type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down

0 comments on commit 464ab32

Please sign in to comment.