diff --git a/lib/Resque/Event.php b/lib/Resque/Event.php index 20072ff..34a224e 100644 --- a/lib/Resque/Event.php +++ b/lib/Resque/Event.php @@ -18,26 +18,27 @@ class Resque_Event * * @param string $event Name of event to be raised. * @param mixed $data Optional, any data that should be passed to each callback. - * @return true + * @return int */ public static function trigger($event, $data = null) { - if (!is_array($data)) { - $data = array($data); - } + $fired = 0; - if (empty(self::$events[$event])) { - return true; - } - - foreach (self::$events[$event] as $callback) { - if (!is_callable($callback)) { - continue; - } - call_user_func_array($callback, $data); - } - - return true; + if (!is_array($data)) { + $data = array($data); + } + + if (!empty(self::$events[$event])) { + foreach (self::$events[$event] as $callback) { + if (!is_callable($callback)) { + continue; + } + $fired++; + call_user_func_array($callback, $data); + } + } + + return $fired; } /** diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index ef7191b..8794dff 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -161,7 +161,7 @@ public function getInstance() } else { if(!class_exists($this->payload['class'])) { throw new Resque_Exception( - 'Could not find job class ' . $this->payload['class'] . '.' + 'Could not find job class ' . $this->payload['class'] . ' (Resque_Job_Creator not loaded).' ); } @@ -171,11 +171,11 @@ public function getInstance() ); } $this->instance = new $this->payload['class'](); + $this->instance->job = $this; + $this->instance->args = $this->getArguments(); + $this->instance->queue = $this->queue; } - $this->instance->job = $this; - $this->instance->args = $this->getArguments(); - $this->instance->queue = $this->queue; return $this->instance; } @@ -188,7 +188,7 @@ public function getInstance() */ public function perform() { - $instance = $this->getInstance(); + $instance = $this->getInstance(); try { Resque_Event::trigger('beforePerform', $this); diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index 0d0e4d3..89f896c 100755 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -49,7 +49,7 @@ class Resque_Worker const LOG_TYPE_CRITICAL = 500; const LOG_TYPE_ALERT = 550; - public $logOutput = STDOUT; + public $logOutput = null; /** * @var int Current log level of this worker. @@ -166,6 +166,9 @@ public function setId($workerId) */ public function __construct($queues) { + if (defined('STDOUT')) { + $this->logOutput = STDOUT; + } if (!is_array($queues)) { $queues = array($queues); } @@ -260,6 +263,9 @@ public function work($interval = 5) $this->child = null; $this->doneWorking(); + + $fired = Resque_Event::trigger('afterdoneworking', $job); + $this->log(array('message' => "afterdoneworking triggered {$fired} callbacks", 'data' => compact('job')), self::LOG_TYPE_INFO); } $this->unregisterWorker(); @@ -374,8 +380,12 @@ protected function startup() */ protected function updateProcLine($status) { - if (function_exists('setproctitle')) { - setproctitle('resque-' . Resque::VERSION . ': ' . $status); + $processTitle = 'resque-' . Resque::VERSION . ': ' . $status; + + if (function_exists('cli_set_process_title')) { + cli_set_process_title($processTitle); + } elseif (function_exists('setproctitle')) { + setproctitle($processTitle); } } @@ -509,9 +519,13 @@ public function pruneDeadWorkers() public function workerPids() { $pids = array(); - exec('ps -A -o pid,comm | grep [r]esque', $cmdOutput); + exec('ps -A -o pid,comm,command | grep [r]esque', $cmdOutput); foreach ($cmdOutput as $line) { list($pids[]) = explode(' ', trim($line), 2); + $cols = explode(' ', trim($line), 3); + if (trim($cols[1] == 'php')) { + $pids[] = trim($cols[0]); + } } return $pids; } @@ -597,6 +611,10 @@ public function log($message, $code = self::LOG_TYPE_INFO) return false; } + if (null === $this->logger && null === $this->logOutput) { + return false; + } + /*if ($this->logger === null) { if ($this->logLevel === self::LOG_NORMAL && $code !== self::LOG_TYPE_DEBUG) { fwrite($this->logOutput, "*** " . $message['message'] . "\n");