예제 #1
0
 public function getJobStatistics(Job $job)
 {
     $statisticData = array();
     $dataPerCharacteristic = array();
     $stmt = $this->em->getConnection()->prepare('SELECT * FROM jms_job_statistics WHERE job_id = :jobId');
     $stmt->execute(array('jobId' => $job->getId()));
     $statistics = $stmt->fetchAll();
     $propertyAccess = PropertyAccess::createPropertyAccessor();
     foreach ($statistics as $row) {
         $dataPerCharacteristic[$propertyAccess->getValue($row, '[characteristic]')][] = array($propertyAccess->getValue($row, '[createdAt]'), $propertyAccess->getValue($row, '[charValue]'));
     }
     if ($dataPerCharacteristic) {
         $statisticData = array(array_merge(array('Time'), $chars = array_keys($dataPerCharacteristic)));
         $startTime = strtotime($dataPerCharacteristic[$chars[0]][0][0]);
         $endTime = strtotime($dataPerCharacteristic[$chars[0]][count($dataPerCharacteristic[$chars[0]]) - 1][0]);
         $scaleFactor = $endTime - $startTime > 300 ? 1 / 60 : 1;
         // This assumes that we have the same number of rows for each characteristic.
         for ($i = 0, $c = count(reset($dataPerCharacteristic)); $i < $c; $i++) {
             $row = array((strtotime($dataPerCharacteristic[$chars[0]][$i][0]) - $startTime) * $scaleFactor);
             foreach ($chars as $name) {
                 $value = (double) $dataPerCharacteristic[$name][$i][1];
                 switch ($name) {
                     case 'memory':
                         $value /= 1024 * 1024;
                         break;
                 }
                 $row[] = $value;
             }
             $statisticData[] = $row;
         }
     }
     return $statisticData;
 }
예제 #2
0
 public function getJobStatistics(Job $job)
 {
     $statisticData = array();
     $dataPerCharacteristic = array();
     $statistics = $this->em->getConnection()->query("SELECT * FROM jms_job_statistics WHERE job_id = " . $job->getId());
     foreach ($statistics as $row) {
         $dataPerCharacteristic[$row['characteristic']][] = array($row['createdAt'], $row['charValue']);
     }
     if ($dataPerCharacteristic) {
         $statisticData = array(array_merge(array('Time'), $chars = array_keys($dataPerCharacteristic)));
         $startTime = strtotime($dataPerCharacteristic[$chars[0]][0][0]);
         $endTime = strtotime($dataPerCharacteristic[$chars[0]][count($dataPerCharacteristic[$chars[0]]) - 1][0]);
         $scaleFactor = $endTime - $startTime > 300 ? 1 / 60 : 1;
         // This assumes that we have the same number of rows for each characteristic.
         for ($i = 0, $c = count(reset($dataPerCharacteristic)); $i < $c; $i++) {
             $row = array((strtotime($dataPerCharacteristic[$chars[0]][$i][0]) - $startTime) * $scaleFactor);
             foreach ($chars as $name) {
                 $value = (double) $dataPerCharacteristic[$name][$i][1];
                 switch ($name) {
                     case 'memory':
                         $value /= 1024 * 1024;
                         break;
                 }
                 $row[] = $value;
             }
             $statisticData[] = $row;
         }
     }
     return $statisticData;
 }
 public function __construct(Job $job, $newState, array $allowedStates = array())
 {
     $msg = sprintf('The Job(id = %d) cannot change from "%s" to "%s". Allowed transitions: ', $job->getId(), $job->getState(), $newState);
     $msg .= count($allowedStates) > 0 ? '"' . implode('", "', $allowedStates) . '"' : '#none#';
     parent::__construct($msg);
     $this->job = $job;
     $this->newState = $newState;
     $this->allowedStates = $allowedStates;
 }
예제 #4
0
 /**
  * @param Job $job
  * @return \Symfony\Component\Process\Process
  */
 public function runJob(Job $job)
 {
     $pb = $this->getCommandProcessBuilder();
     $pb->add($job->getCommand())->add('--jms-job-id=' . $job->getId());
     foreach ($job->getArgs() as $arg) {
         $pb->add($arg);
     }
     $proc = $pb->getProcess();
     $proc->start();
     return $proc;
 }
 /**
  * @Route("/{id}", name = "jms_jobs_details")
  * @Template
  */
 public function detailsAction(Job $job)
 {
     $relatedEntities = array();
     foreach ($job->getRelatedEntities() as $entity) {
         $class = ClassUtils::getClass($entity);
         $relatedEntities[] = array('class' => $class, 'id' => json_encode($this->registry->getManagerForClass($class)->getClassMetadata($class)->getIdentifierValues($entity)), 'raw' => $entity);
     }
     $statisticData = $statisticOptions = array();
     if ($this->statisticsEnabled) {
         $dataPerCharacteristic = array();
         foreach ($this->registry->getManagerForClass('JMSJobQueueBundle:Job')->getConnection()->query("SELECT * FROM jms_job_statistics WHERE job_id = " . $job->getId()) as $row) {
             $dataPerCharacteristic[$row['characteristic']][] = array($row['createdAt'], $row['charValue']);
         }
         if ($dataPerCharacteristic) {
             $statisticData = array(array_merge(array('Time'), $chars = array_keys($dataPerCharacteristic)));
             $startTime = strtotime($dataPerCharacteristic[$chars[0]][0][0]);
             $endTime = strtotime($dataPerCharacteristic[$chars[0]][count($dataPerCharacteristic[$chars[0]]) - 1][0]);
             $scaleFactor = $endTime - $startTime > 300 ? 1 / 60 : 1;
             // This assumes that we have the same number of rows for each characteristic.
             for ($i = 0, $c = count(reset($dataPerCharacteristic)); $i < $c; $i++) {
                 $row = array((strtotime($dataPerCharacteristic[$chars[0]][$i][0]) - $startTime) * $scaleFactor);
                 foreach ($chars as $name) {
                     $value = (double) $dataPerCharacteristic[$name][$i][1];
                     switch ($name) {
                         case 'memory':
                             $value /= 1024 * 1024;
                             break;
                     }
                     $row[] = $value;
                 }
                 $statisticData[] = $row;
             }
         }
     }
     return array('job' => $job, 'relatedEntities' => $relatedEntities, 'incomingDependencies' => $this->getRepo()->getIncomingDependencies($job), 'statisticData' => $statisticData, 'statisticOptions' => $statisticOptions);
 }
 private function getJobIdsOfIncomingDependencies(Job $job)
 {
     $jobIds = $this->_em->getConnection()->executeQuery("SELECT source_job_id FROM jms_job_dependencies WHERE dest_job_id = :id", array('id' => $job->getId()))->fetchAll(\PDO::FETCH_COLUMN);
     return $jobIds;
 }