public static function human_time_diff($from, $to = null)
{
$to = $to ?: time();
$diff = (int) abs($to - $from);
if ($diff < self::MINUTE_IN_SECONDS) {
$since = array($diff, 'sec');
} elseif ($diff < self::HOUR_IN_SECONDS) {
$since = array(round($diff / self::MINUTE_IN_SECONDS), 'min');
} elseif ($diff < self::DAY_IN_SECONDS and $diff >= self::HOUR_IN_SECONDS) {
$since = array(round($diff / self::HOUR_IN_SECONDS), 'hour');
} elseif ($diff < self::WEEK_IN_SECONDS and $diff >= self::DAY_IN_SECONDS) {
$since = array(round($diff / self::DAY_IN_SECONDS), 'day');
} elseif ($diff < 30 * self::DAY_IN_SECONDS and $diff >= self::WEEK_IN_SECONDS) {
$since = array(round($diff / self::WEEK_IN_SECONDS), 'week');
} elseif ($diff < self::YEAR_IN_SECONDS and $diff >= 30 * self::DAY_IN_SECONDS) {
$since = array(round($diff / (30 * self::DAY_IN_SECONDS)), 'month');
} elseif ($diff >= self::YEAR_IN_SECONDS) {
$since = array(round($diff / self::YEAR_IN_SECONDS), 'year');
}
if ($since[0] <= 1) {
$since[0] = 1;
}
return $since[0] . ' ' . $since[1] . ($since[0] == 1 ? '' : 's');
}
protected function execute(InputInterface $input, OutputInterface $output) { $workers = Resque\Worker::hostWorkers(); if (empty($workers)) { $this->log('<warn>There are no workers on this host.</warn>'); return; } $table = new Resque\Helpers\Table($this); $table->setHeaders(array('#', 'Status', 'ID', 'Running for', 'Running job', 'P', 'C', 'F', 'Interval', 'Timeout', 'Memory (Limit)')); foreach ($workers as $i => $worker) { $packet = $worker->getPacket(); $table->addRow(array($i + 1, Resque\Worker::$statusText[$packet['status']], (string) $worker, Resque\Helpers\Util::human_time_diff($packet['started']), !empty($packet['job_id']) ? $packet['job_id'] . ' for ' . Resque\Helpers\Util::human_time_diff($packet['job_started']) : '-', $packet['processed'], $packet['cancelled'], $packet['failed'], $packet['interval'], $packet['timeout'], Resque\Helpers\Util::bytes($packet['memory']) . ' (' . $packet['memory_limit'] . ' MB)')); } $this->log((string) $table); }