Esempio n. 1
0
 /**
  * run a specific job.
  *
  * @param string|object $run_job
  * @return bool
  * @throws \Thallium\Controllers\ExceptionController
  */
 public function runJob($run_job)
 {
     global $thallium, $mbus;
     if (!isset($run_job) || empty($run_job) || !is_string($run_job) && !is_object($run_job)) {
         static::raiseError(__METHOD__ . '(), $run_job parameter is invalid!');
         return false;
     }
     if (is_object($run_job) && !is_a($run_job, 'Thallium\\Models\\JobModel')) {
         static::raiseError(__METHOD__ . '(), $run_job is not a JobModel!');
         return false;
     }
     if (is_string($run_job) && !$thallium->isValidGuidSyntax($run_job)) {
         static::raiseError(__METHOD__ . '(), $run_job is not a valid GUID!');
         return false;
     }
     if (is_string($run_job)) {
         try {
             $job = new \Thallium\Models\JobModel(array('guid' => $run_job));
         } catch (\Exception $e) {
             static::raiseError(__METHOD__ . '(), failed to load JobModel!', false, $e);
             return false;
         }
     } else {
         $job =& $run_job;
     }
     if (($command = $job->getCommand()) === false) {
         static::raiseError(get_class($job) . '::getCommand() returned false!');
         return false;
     }
     if (!isset($command) || empty($command) || !is_string($command)) {
         static::raiseError(get_class($job) . '::getCommand() returned invalid data!');
         return false;
     }
     if (!$this->isRegisteredHandler($command)) {
         static::raiseError(__METHOD__ . "(), there is no handler for {$command}!");
         return false;
     }
     if (($handler = $this->getHandler($command)) === false) {
         static::raiseError(__CLASS__ . '::getHandler() returned false!');
         return false;
     }
     if (!isset($handler) || empty($handler) || !is_string($handler) && !is_array($handler) && !is_callable($handler) && !is_object($handler) || is_array($handler) && (!isset($handler[0]) || empty($handler[0]) || !is_object($handler[0]) || !isset($handler[1]) || empty($handler[1]) || !is_string($handler[1])) || is_object($handler) && !is_a($handler, '\\Closure')) {
         static::raiseError(__CLASS__ . '::getHandler() returned invalid data!');
         return false;
     }
     if (!is_callable($handler, true)) {
         static::raiseError(__METHOD__ . '(), handler is not callable!');
         return false;
     }
     if (!$job->hasSessionId()) {
         if (($state = $mbus->suppressOutboundMessaging(true)) === null) {
             static::raiseError(get_class($mbus) . '::suppressOutboundMessaging() returned null!');
             return false;
         }
     }
     if (!call_user_func($handler, $job)) {
         static::raiseError(get_class($handler[0]) . "::{$handler[1]}() returned false!");
         return false;
     }
     if (!$job->hasSessionId()) {
         if ($mbus->suppressOutboundMessaging($state) === null) {
             static::raiseError(get_class($mbus) . '::suppressOutboundMessaging() returned null!');
             return false;
         }
     }
     return true;
 }