Ejemplo 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;
 }
Ejemplo n.º 2
0
 /**
  * return the session-id that is bound to a specific job.
  *
  * @param string|null $job_guid
  * @return string|bool
  * @throws \Thallium\Controllers\ExceptionController if an error occurs.
  */
 protected function getSessionIdFromJob($job_guid = null)
 {
     global $thallium, $jobs;
     if (!isset($job_guid) || empty($job_guid)) {
         if (($job_guid = $jobs->getCurrentJob()) === false) {
             static::raiseError(get_class($jobs) . '::getCurrentJob() returned false!');
             return false;
         }
         if (!isset($job_guid) || empty($job_guid)) {
             static::raiseError(__METHOD__ . '(), no job found to work on!');
             return false;
         }
     }
     if (!$thallium->isValidGuidSyntax($job_guid)) {
         static::raiseError(get_class($thallium) . '::isValidGuidSyntax() returned false!');
         return false;
     }
     try {
         $job = new \Thallium\Models\JobModel(array(FIELD_GUID => $job_guid));
     } catch (\Exception $e) {
         static::raiseError(__METHOD__ . '(), failed to load JobModel!', false, $e);
         return false;
     }
     if (($sessionid = $job->getSessionId()) === false) {
         static::raiseError(get_class($job) . '::getSessionId() returned false!');
         return false;
     }
     return $sessionid;
 }
Ejemplo n.º 3
0
 public function deleteJob($job_guid)
 {
     global $thallium;
     if (!isset($job_guid) || empty($job_guid) || !$thallium->isValidGuidSyntax($job_guid)) {
         static::raiseError(__METHOD__ . ', first parameter has to be a valid GUID!');
         return false;
     }
     try {
         $job = new \Thallium\Models\JobModel(array('guid' => $job_guid));
     } catch (\Exception $e) {
         static::raiseError(__METHOD__ . ", failed to load JobModel(null, {$job_guid})");
         return false;
     }
     if (!$job->delete()) {
         static::raiseError(get_class($job) . '::delete() returned false!');
         return false;
     }
     if ($this->hasCurrentJob() && ($cur_guid = $this->getCurrentJob())) {
         if ($cur_guid == $job_guid) {
             $this->clearCurrentJob();
         }
     }
     return true;
 }