Esempio n. 1
0
 /**
  * Track a job status.
  *
  * @since 2.1.0
  * @return void
  * @return bool False is tracking the job status fails.
  */
 public function track()
 {
     $this->out('<info>' . __d('cake_resque', 'Tracking job status') . '</info>');
     if (isset($this->args[0])) {
         $jobId = $this->args[0];
     } else {
         $this->out('<error>' . __d('cake_resque', 'Please provide a valid job ID') . "</error>\n");
         return false;
     }
     $jobStatus = CakeResque::getJobStatus($jobId);
     if ($jobStatus === false) {
         $this->out(__d('cake_resque', 'Status') . ' : <warning>' . __d('cake_resque', 'Unknown') . '</warning>');
     } else {
         $statusName = [Resque_Job_Status::STATUS_WAITING => __d('cake_resque', 'waiting'), Resque_Job_Status::STATUS_RUNNING => __d('cake_resque', 'running'), Resque_Job_Status::STATUS_FAILED => __d('cake_resque', 'failed'), Resque_Job_Status::STATUS_COMPLETE => __d('cake_resque', 'complete')];
         $statusClass = [Resque_Job_Status::STATUS_WAITING => 'info', Resque_Job_Status::STATUS_RUNNING => 'info', Resque_Job_Status::STATUS_FAILED => 'error', Resque_Job_Status::STATUS_COMPLETE => 'success'];
         if (Configure::read('CakeResque.Scheduler.enabled') === true) {
             $statusClass[Status::STATUS_SCHEDULED] = 'info';
             $statusName[Status::STATUS_SCHEDULED] = __d('cake_resque', 'scheduled');
         }
         $this->out(sprintf(__d('cake_resque', 'Status') . ' : <%1$s>%2$s</%1$s>', isset($statusClass[$jobStatus]) ? $statusClass[$jobStatus] : 'warning', isset($statusName[$jobStatus]) ? $statusName[$jobStatus] : __d('cake_resque', 'Unknown')));
         if ($jobStatus === Resque_Job_Status::STATUS_FAILED) {
             $log = CakeResque::getFailedJobLog($jobId);
             if (!empty($log)) {
                 $this->hr();
                 $this->out('<comment>' . __d('cake_resque', 'Failed job details') . '</comment>');
                 $this->hr();
                 foreach ($log as $key => $value) {
                     $this->out(sprintf("<info>%-10s: </info>", strtoupper($key)), 0);
                     if (is_string($value)) {
                         $this->out($value);
                     } else {
                         $this->out('');
                         foreach ($value as $sKey => $sValue) {
                             $this->out(sprintf("    <info>%5s : </info>", $sKey), 0);
                             if (is_string($sValue)) {
                                 $this->out($sValue);
                             } else {
                                 $this->out(str_replace("\n", "\n            ", var_export($sValue, true)));
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->out('');
 }