Skip to content

Commit 243e0d5

Browse files
committed
Add status callback which is available in net_gearamn 2.1.0
1 parent eab0220 commit 243e0d5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Bridge/GearmanPearManager.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,41 @@ protected function start_lib_worker($worker_list, $timeouts = array()) {
9696
$this->worker->attachCallback(array($this, 'job_start'), \Net_Gearman_Worker::JOB_START);
9797
$this->worker->attachCallback(array($this, 'job_complete'), \Net_Gearman_Worker::JOB_COMPLETE);
9898
$this->worker->attachCallback(array($this, 'job_fail'), \Net_Gearman_Worker::JOB_FAIL);
99+
$this->worker->attachCallback(array($this, 'status'), \Net_Gearman_Worker::WORKER_STATUS);
99100

100101
$this->start_time = time();
101102

102103
$this->worker->beginWork(array($this, "monitor"));
103104

104105
}
105106

107+
/**
108+
* Callback for worker status
109+
*
110+
* @param <type> $message The message
111+
* @param <type> $server The server
112+
* @param <type> $connected The connected
113+
* @param int $failed_conns The failed conns
114+
*/
115+
public function status($message, $server, $connected, $failed_conns) {
116+
117+
$level = GearmanManager::LOG_LEVEL_DEBUG;
118+
119+
if (!empty($server) && (!$connected || $failed_conns > 0)) {
120+
$level = GearmanManager::LOG_LEVEL_WORKER_INFO;
121+
}
122+
123+
if (!empty($server)) {
124+
$message .= " (server: $server)";
125+
}
126+
127+
if (!empty($failed_conns)) {
128+
$message .= " (failed connections: $failed_conns)";
129+
}
130+
131+
$this->log($message, $level);
132+
}
133+
106134
/**
107135
* Monitor call back for worker. Return true to stop worker
108136
*

0 commit comments

Comments
 (0)