Skip to content

Commit

Permalink
Use async signals with PCNTL (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
tspencer244 authored Nov 13, 2023
1 parent d9e7e8b commit bc5ea60
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
3 changes: 2 additions & 1 deletion bin/resque
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ if($count > 1) {
$children[$pid] = 1;
while (count($children) == $count) {
if (!isset($registered)) {
declare(ticks=1);
pcntl_async_signals(true);

foreach ($all_signals as $signal) {
pcntl_signal($signal, "cleanup_children");
}
Expand Down
15 changes: 1 addition & 14 deletions lib/Resque/Worker.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(ticks=1);

/**
* Resque worker that handles checking queues for jobs, fetching them
* off the queues, running them and handling the result.
Expand Down Expand Up @@ -167,10 +165,6 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
$this->updateProcLine('Starting');
$this->startup();

if(function_exists('pcntl_signal_dispatch')) {
pcntl_signal_dispatch();
}

while(true) {
if($this->shutdown) {
break;
Expand Down Expand Up @@ -247,14 +241,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
$this->logger->log(Psr\Log\LogLevel::INFO, $status);

// Wait until the child process finishes before continuing
while (pcntl_wait($status, WNOHANG) === 0) {
if(function_exists('pcntl_signal_dispatch')) {
pcntl_signal_dispatch();
}

// Pause for a half a second to conserve system resources
usleep(500000);
}
pcntl_wait($status);

if (pcntl_wifexited($status) !== true) {
$job->fail(new Resque_Job_DirtyExitException('Job exited abnormally'));
Expand Down
2 changes: 0 additions & 2 deletions lib/ResqueScheduler/Worker.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(ticks=1);

/**
* ResqueScheduler worker to handle scheduling of delayed tasks.
*
Expand Down

0 comments on commit bc5ea60

Please sign in to comment.