public function workerDiagnostics(&$workerIssueCount) { $this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis()); $workers = $this->ResqueStatus->getWorkers(); if (function_exists('posix_getpwuid')) { $currentUser = posix_getpwuid(posix_geteuid()); $currentUser = $currentUser['name']; } else { $currentUser = trim(shell_exec('whoami')); } $worker_array = array('cache' => array('ok' => true), 'default' => array('ok' => true), 'email' => array('ok' => true), 'scheduler' => array('ok' => true)); $procAccessible = file_exists('/proc'); foreach ($workers as $pid => $worker) { $entry = $worker['type'] == 'regular' ? $worker['queue'] : $worker['type']; $correct_user = $currentUser === $worker['user']; if (!is_numeric($pid)) { throw new MethodNotAllowedException('Non numeric PID found.'); } if ($procAccessible) { $alive = $correct_user ? file_exists('/proc/' . addslashes($pid)) : false; } else { $alive = 'N/A'; } $ok = true; if (!$alive || !$correct_user) { $ok = false; $workerIssueCount++; $worker_array[$entry]['ok'] = false; } $worker_array[$entry]['workers'][] = array('pid' => $pid, 'user' => $worker['user'], 'alive' => $alive, 'correct_user' => $correct_user, 'ok' => $ok); } foreach ($worker_array as $k => &$queue) { if ($k != 'scheduler') { $worker_array[$k]['jobCount'] = CakeResque::getQueueSize($k); } if (!isset($queue['workers'])) { $workerIssueCount++; $queue['ok'] = false; } } $worker_array['proc_accessible'] = $procAccessible; return $worker_array; }
public function workerDiagnostics(&$workerIssueCount) { $this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis()); $workers = $this->ResqueStatus->getWorkers(); $currentUser = get_current_user(); $worker_array = array('cache' => array('ok' => true), 'default' => array('ok' => true), 'email' => array('ok' => true), 'scheduler' => array('ok' => true)); foreach ($workers as $pid => $worker) { $entry = $worker['type'] == 'regular' ? $worker['queue'] : $worker['type']; $correct_user = $currentUser === $worker['user']; if (!is_numeric($pid)) { throw new MethodNotAllowedException('Non numeric PID found.'); } $alive = $correct_user ? substr_count(trim(shell_exec('ps -p ' . $pid)), PHP_EOL) > 0 : false; $ok = true; if (!$alive || !$correct_user) { $ok = false; $workerIssueCount++; $worker_array[$entry]['ok'] = false; } $worker_array[$entry]['workers'][] = array('pid' => $pid, 'user' => $worker['user'], 'alive' => $alive, 'correct_user' => $correct_user, 'ok' => $ok); } foreach ($worker_array as $k => &$queue) { if ($k != 'scheduler') { $worker_array[$k]['jobCount'] = CakeResque::getQueueSize($k); } if (!isset($queue['workers'])) { $workerIssueCount++; $queue['ok'] = false; } } return $worker_array; }