Beispiel #1
0
 public function abortJob(Uws_Model_Resource_JobSummaryType &$job)
 {
     if (isset($job->handledByAbstract)) {
         $resource = new Uws_Model_Resource_UWSJobs();
         $resource->updateRow($job->jobId, array("phase" => "ABORTED"));
     } else {
         $this->abortJobImpl($job);
     }
 }
Beispiel #2
0
 public function runJob(Uws_Model_Resource_JobSummaryType &$job)
 {
     // obtain queue information
     $resource = Query_Model_Resource_AbstractQuery::factory();
     $queues = array();
     if ($resource::$hasQueues === true && isset($job->parameters['queue'])) {
         $queues = $resource->fetchQueues();
         // find the queue
         foreach ($queues as $queue) {
             if ($queue['name'] === $job->parameters['queue']->value) {
                 $job->executionDuration = $queue['timeout'];
                 break;
             }
         }
     } else {
         if ($resource::$hasQueues === true) {
             // no queue has been specified, but we support queues - if executionDuration is 0, use default queue
             // otherwise find the desired queue
             $queues = $resource->fetchQueues();
             if ($job->executionDuration === 0) {
                 // use default queue here
                 $queue = Daiquiri_Config::getInstance()->query->query->qqueue->defaultQueue;
                 foreach ($queues as $currQueue) {
                     if ($currQueue['name'] === $queue) {
                         $job->executionDuration = $currQueue['timeout'];
                         $job->addParameter("queue", $currQueue['name']);
                         break;
                     }
                 }
             } else {
                 // find a queue that matches the request (i.e. is nearest to the request)
                 $maxQueueTimeout = 0;
                 $maxQueue = false;
                 $deltaQueue = 9.999999999999999E+33;
                 $queue = false;
                 foreach ($queues as $currQueue) {
                     if ($currQueue['timeout'] > $maxQueue) {
                         $maxQueueTimeout = $currQueue['timeout'];
                         $maxQueue = $currQueue;
                     }
                     if ($currQueue['timeout'] >= $job->executionDuration) {
                         $currDelta = $currQueue['timeout'] - $job->executionDuration;
                         if ($currDelta < $deltaQueue) {
                             $queue = $currQueue;
                             $deltaQueue = $currDelta;
                         }
                     }
                 }
                 if ($queue === false) {
                     $queue = $maxQueue;
                 }
                 $job->addParameter("queue", $currQueue['name']);
                 $job->executionDuration = $currQueue['timeout'];
             }
         }
     }
     // now check if everything is there that we need...
     $tablename = null;
     $sql = null;
     $queue = null;
     $errors = array();
     if (!isset($job->parameters['query']) || $resource::$hasQueues === true && !isset($job->parameters['queue'])) {
         // throw error
         $job->addError("Incomplete job");
         $resource = new Uws_Model_Resource_UWSJobs();
         $resource->updateRow($job->jobId, array("phase" => "ERROR", "errorSummary" => Zend_Json::encode($job->errorSummary)));
         return;
     }
     if (isset($job->parameters['table'])) {
         $tablename = $job->parameters['table']->value;
     }
     $sql = $job->parameters['query']->value;
     if ($resource::$hasQueues === true) {
         $queue = $job->parameters['queue']->value;
     }
     // submit job
     // validate query
     $job->resetErrors();
     $model = new Query_Model_Query();
     try {
         if ($model->validate($sql, false, $tablename, $errors) !== true) {
             //throw error
             foreach ($errors as $error) {
                 $job->addError($error);
             }
             $resource = new Uws_Model_Resource_UWSJobs();
             $resource->updateRow($job->jobId, array("phase" => "ERROR", "errorSummary" => Zend_Json::encode($job->errorSummary)));
             return;
         }
     } catch (Exception $e) {
         // throw error
         $job->addError($e->getMessage());
         $resource = new Uws_Model_Resource_UWSJobs();
         $resource->updateRow($job->jobId, array("phase" => "ERROR", "errorSummary" => Zend_Json::encode($job->errorSummary)));
         return;
     }
     // submit query
     if ($resource::$hasQueues === true) {
         $response = $model->query($sql, false, $tablename, array("queue" => $queue, "jobId" => $job->jobId));
     } else {
         $response = $model->query($sql, false, $tablename, array("jobId" => $job->jobId));
     }
     if ($response['status'] !== 'ok') {
         // throw error
         foreach ($response['errors'] as $error) {
             $job->addError($error);
         }
         $resource = new Uws_Model_Resource_UWSJobs();
         $resource->updateRow($job->jobId, array("phase" => "ERROR", "errorSummary" => Zend_Json::encode($job->errorSummary)));
         return;
     }
     // clean up stuff (basically just remove the job in the temorary UWS job store - if we are here
     // everything has been handeled by the queue)
     $resource = new Uws_Model_Resource_UWSJobs();
     $resource->deleteRow($job->jobId);
 }