Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

#self-reference Added use of self:: reference, so CakeResqueShell class ... #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Console/Command/CakeResqueShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function getOptionParser() {
return parent::getOptionParser()
->description(
__d('cake_resque', "A Shell to manage PHP Resque") . "\n" .
__d('cake_resque', "Version " . CakeResqueShell::VERSION) . "\n" .
__d('cake_resque', "Version " . self::VERSION) . "\n" .
"Wan Chen (" . date('Y') . ")"
)
->addSubcommand('start', array(
Expand Down Expand Up @@ -328,7 +328,7 @@ public function enqueue() {
}

$result = call_user_func_array(
CakeResqueShell::$cakeResque . '::enqueue',
self::$cakeResque . '::enqueue',
array($this->args[0], $this->args[1], explode(',', $this->args[2]))
);
$this->out('<success>' . __d('cake_resque', 'Succesfully enqueued Job #%s', $result) . '</success>');
Expand All @@ -351,7 +351,7 @@ public function enqueueIn() {
}

$result = call_user_func_array(
CakeResqueShell::$cakeResque . '::enqueueIn',
self::$cakeResque . '::enqueueIn',
array($this->args[0], $this->args[1], $this->args[2], explode(',', $this->args[3]), (isset($this->args[4]) ? (bool)$this->args[4] : false))
);

Expand All @@ -375,7 +375,7 @@ public function enqueueAt() {
}

$result = call_user_func_array(
CakeResqueShell::$cakeResque . '::enqueueAt',
self::$cakeResque . '::enqueueAt',
array($this->args[0], $this->args[1], $this->args[2], explode(',', $this->args[3]), (isset($this->args[4]) ? (bool)$this->args[4] : false))
);
$this->out('<success>' . __d('cake_resque', 'Succesfully scheduled Job #%s', $result) . '</success>');
Expand Down Expand Up @@ -557,7 +557,7 @@ public function start($args = null, $scheduler = false) {
while ($attempt-- > 0) {
for ($j = 0; $j < 3;$j++) {
$this->out(".", 0);
usleep(CakeResqueShell::$checkStartedWorkerBufferTime);
usleep(self::$checkStartedWorkerBufferTime);
}

if (false !== $pid = $this->_checkStartedWorker($pidFile)) {
Expand Down Expand Up @@ -625,16 +625,16 @@ public function stop() {

$queues = $worker->queues(false);
foreach ($queues as $queue) {
$size = call_user_func_array(CakeResqueShell::$cakeResque . '::getQueueSize', array($queue));
$size = call_user_func_array(self::$cakeResque . '::getQueueSize', array($queue));
if ($size === 0) {
call_user_func_array(CakeResqueShell::$cakeResque . '::removeQueue', array($queue));
call_user_func_array(self::$cakeResque . '::removeQueue', array($queue));
}
}
};

return $this->_sendSignal(
__d('cake_resque', 'Stopping workers') . ($this->params['force'] ? ' (' . __d('cake_resque', 'force') . ')' : ''),
call_user_func(CakeResqueShell::$cakeResque . '::getWorkers'),
call_user_func(self::$cakeResque . '::getWorkers'),
__d('cake_resque', 'There is no workers to stop ...'),
__d('cake_resque', 'Workers list'),
__d('cake_resque', 'Stop all workers'),
Expand Down Expand Up @@ -670,7 +670,7 @@ public function cleanup() {

return $this->_sendSignal(
__d('cake_resque', 'Cleaning up workers'),
call_user_func(CakeResqueShell::$cakeResque . '::getWorkers'),
call_user_func(self::$cakeResque . '::getWorkers'),
__d('cake_resque', 'There is no active workers to clean up ...'),
__d('cake_resque', 'Active workers list'),
__d('cake_resque', 'Clean up all workers'),
Expand Down Expand Up @@ -710,7 +710,7 @@ public function pause() {

// Active workers
$this->debug(__d('cake_resque', 'Fetching list of active workers'));
$activeWorkers = call_user_func(CakeResqueShell::$cakeResque . '::getWorkers');
$activeWorkers = call_user_func(self::$cakeResque . '::getWorkers');
array_walk($activeWorkers, function (&$worker) {
$worker = (string)$worker;
});
Expand Down Expand Up @@ -807,7 +807,7 @@ protected function _sendSignal($title, $workers, $noWorkersMessage, $listTitle,
$formatListItem = function ($worker, $i) use ($ResqueStatus) {
App::uses('CakeTime', 'Utility');
return sprintf(" [%3d] - %s, started %s", $i, $ResqueStatus->isSchedulerWorker($worker) ? '<comment>**Scheduler Worker**</comment>' : $worker,
CakeTime::timeAgoInWords(call_user_func(CakeResqueShell::$cakeResque . '::getWorkerStartDate', $worker)));
CakeTime::timeAgoInWords(call_user_func(self::$cakeResque . '::getWorkerStartDate', $worker)));
};
}

Expand Down Expand Up @@ -946,10 +946,10 @@ public function restart() {
public function stats() {
$ResqueStatus = $this->ResqueStatus;

$workers = call_user_func(CakeResqueShell::$cakeResque . '::getWorkers');
$workers = call_user_func(self::$cakeResque . '::getWorkers');

// List of all queues
$queues = array_unique(call_user_func(CakeResqueShell::$cakeResque . '::getQueues'));
$queues = array_unique(call_user_func(self::$cakeResque . '::getQueues'));

// List of queues monitored by a worker
$activeQueues = array();
Expand All @@ -976,7 +976,7 @@ public function stats() {
$count = array();
$this->out('<info>' . __d('cake_resque', 'Queues Stats') . '</info>');
for ($i = count($queues) - 1; $i >= 0; --$i) {
$count[$queues[$i]] = call_user_func_array(CakeResqueShell::$cakeResque . '::getQueueSize', array($queues[$i]));
$count[$queues[$i]] = call_user_func_array(self::$cakeResque . '::getQueueSize', array($queues[$i]));
if (!in_array($queues[$i], $activeQueues) && $count[$queues[$i]] == 0) {
unset($queues[$i]);
}
Expand All @@ -1002,7 +1002,7 @@ public function stats() {
continue;
}
$this->out("\t* <bold>" . (string)$worker . '</bold>' . (in_array((string)$worker, $pausedWorkers) ? ' <warning>(' . __d('cake_resque', 'paused') . ')</warning>' : ''));
$this->out("\t - " . __d('cake_resque', 'Started on') . " : " . call_user_func(CakeResqueShell::$cakeResque . '::getWorkerStartDate', $worker));
$this->out("\t - " . __d('cake_resque', 'Started on') . " : " . call_user_func(self::$cakeResque . '::getWorkerStartDate', $worker));
$this->out("\t - " . __d('cake_resque', 'Processed Jobs') . " : " . $worker->getStat('processed'));
$worker->getStat('failed') == 0
? $this->out("\t - " . __d('cake_resque', 'Failed Jobs') . " : " . $worker->getStat('failed'))
Expand All @@ -1017,7 +1017,7 @@ public function stats() {
foreach ($schedulerWorkers as $worker) {
$schedulerWorker = new ResqueScheduler\ResqueScheduler();
$delayedJobCount = $schedulerWorker->getDelayedQueueScheduleSize();
$this->out("\t - " . __d('cake_resque', 'Started on') . " : " . call_user_func(CakeResqueShell::$cakeResque . '::getWorkerStartDate', $worker));
$this->out("\t - " . __d('cake_resque', 'Started on') . " : " . call_user_func(self::$cakeResque . '::getWorkerStartDate', $worker));
$this->out("\t - " . __d('cake_resque', 'Delayed Jobs') . " : " . $delayedJobCount);

if ($delayedJobCount > 0) {
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public function track() {
return false;
}

$jobStatus = call_user_func(CakeResqueShell::$cakeResque . '::getJobStatus', $jobId);
$jobStatus = call_user_func(self::$cakeResque . '::getJobStatus', $jobId);

if ($jobStatus === false) {
$this->out(__d('cake_resque', 'Status') . ' : <warning>' . __d('cake_resque', 'Unknown') . '</warning>');
Expand Down Expand Up @@ -1087,7 +1087,7 @@ public function track() {
);

if ($jobStatus === Resque_Job_Status::STATUS_FAILED) {
$log = call_user_func(CakeResqueShell::$cakeResque . '::getFailedJobLog', $jobId);
$log = call_user_func(self::$cakeResque . '::getFailedJobLog', $jobId);
if (!empty($log)) {
$this->hr();
$this->out('<comment>' . __d('cake_resque', 'Failed job details') . '</comment>');
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public function clear() {
$this->out('<info>' . __d('cake_resque', 'Clearing queues') . '</info>');

// List of all queues
$queues = array_unique(call_user_func(CakeResqueShell::$cakeResque . '::getQueues'));
$queues = array_unique(call_user_func(self::$cakeResque . '::getQueues'));
if (empty($queues)) {
$this->out(__d('cake_resque', 'There is no queues to clear'));
return false;
Expand All @@ -1146,7 +1146,7 @@ public function clear() {
$this->out(__d('cake_resque', 'Queues list') . ':');
$i = 1;
foreach ($queues as $queue) {
$this->out(sprintf(" [%3d] - %-'.20s<bold>%'.9s</bold> jobs", $i++, $queue, number_format(call_user_func_array(CakeResqueShell::$cakeResque . '::getQueueSize', array($queue)))));
$this->out(sprintf(" [%3d] - %-'.20s<bold>%'.9s</bold> jobs", $i++, $queue, number_format(call_user_func_array(self::$cakeResque . '::getQueueSize', array($queue)))));
}

$options = range(1, $i - 1);
Expand All @@ -1173,10 +1173,10 @@ public function clear() {

$this->out(__d('cake_resque', 'Clearing %s ... ', $queue), 0);

$cleared = call_user_func_array(CakeResqueShell::$cakeResque . '::clearQueue', array($queue));
$cleared = call_user_func_array(self::$cakeResque . '::clearQueue', array($queue));

if ($cleared) {
call_user_func_array(CakeResqueShell::$cakeResque . '::removeQueue', array($queue));
call_user_func_array(self::$cakeResque . '::removeQueue', array($queue));
$this->out('<success>' . __d('cake_resque', 'Done') . '</success>');
} else {
$this->out('<error>' . __d('cake_resque', 'Fail') . '</error>');
Expand Down