Beispiel #1
0
 /**
  * Allows a cron job to be set to enabled or disabled
  * 
  * Params
  * ===========================    
  * Required:
  *   - name: The name of the cron job
  *   - status: Either 'enabled' or 'disabled'
  *
  */
 public function put($params)
 {
     $this->checkForEmptyParams(array('name', 'status'), $params);
     $status = strtolower($params['status']);
     if (!in_array($status, array('enabled', 'disabled'))) {
         throw new Ot_Exception_Data('msg-error-invalidStatus');
     }
     $cron = new Ot_Model_DbTable_CronStatus();
     return $cron->setCronStatus($params['name'], $status);
 }
Beispiel #2
0
 /**
  * Dispatches the cron jobs
  *
  * @param int $
  */
 public function dispatch($jobKey = null)
 {
     $register = new Ot_Cron_JobRegister();
     $cs = new Ot_Model_DbTable_CronStatus();
     if (!is_null($jobKey)) {
         $thisJob = $register->getJob($jobKey);
         if (is_null($jobKey)) {
             throw new Exception('Job not found');
         }
         if (!$cs->isEnabled($thisJob->getKey())) {
             throw new Ot_Exception('Job is disabled and cannot be run');
         }
         $lastRunDt = $cs->getLastRunDt($thisJob->getKey());
         $jobObj = $thisJob->getJobObj();
         // make sure job isn't already running
         if (($pid = Ot_Cron_Lock::lock($thisJob->getKey())) == FALSE) {
             return;
         }
         $jobObj->execute($lastRunDt);
         Ot_Cron_Lock::unlock($thisJob->getKey());
         $cs->executed($thisJob->getKey(), time());
         return;
     }
     $now = time();
     $jobs = $register->getJobs();
     foreach ($jobs as $job) {
         if ($this->shouldExecute($job->getSchedule(), $now)) {
             if (!$cs->isEnabled($job->getKey())) {
                 continue;
             }
             $lastRunDt = $cs->getLastRunDt($job->getKey());
             $jobObj = $job->getJobObj();
             if (($pid = Ot_Cron_Lock::lock($job->getKey())) == FALSE) {
                 continue;
             }
             $jobObj->execute($lastRunDt);
             Ot_Cron_Lock::unlock($job->getKey());
             $cs->executed($job->getKey(), time());
         }
     }
 }
 /**
  * Toggles the status of the selected cron job
  *
  */
 public function toggleAction()
 {
     $jobKey = $this->_getParam('jobKey', null);
     if (is_null($jobKey)) {
         throw new Ot_Exception_Input('msg-error-nameNotSet');
     }
     $status = $this->_getParam('status', null);
     if (is_null($status) || !in_array($status, array('enabled', 'disabled'))) {
         throw new Ot_Exception_Input('Status not set in the query string');
     }
     if ($this->_request->isPost()) {
         $cs = new Ot_Model_DbTable_CronStatus();
         $cs->setCronStatus($jobKey, $status);
         $logOptions = array('attributeName' => 'cronName', 'attributeId' => $jobKey);
         $this->_helper->log(Zend_Log::INFO, 'Cronjob ' . $jobKey . ' was set to ' . $status . '.', $logOptions);
         $this->_helper->redirector->gotoRoute(array('controller' => 'cron'), 'ot', true);
     } else {
         throw new Ot_Exception_Access('You are not allowed to access this method directly');
     }
 }