protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $start_time = time();
     while (true) {
         try {
             $query = JenkinsRunQuery::create();
             $query->filterByLaunchDelayed(array('max' => 'now'));
             $jenkinsFactory = new Jenkins_Factory();
             $runs = $query->find();
             foreach ($runs as $run) {
                 /** @var JenkinsRun $run */
                 $user = $run->getJenkinsGroupRun()->getsfGuardUser();
                 $jenkinsUrl = $user->getProfile()->getJenkinsUrl();
                 $jenkins = $jenkinsFactory->build($jenkinsUrl);
                 if (!$jenkins->isAvailable()) {
                     $this->log(sprintf('%s is unreachable', $jenkinsUrl));
                     continue;
                 }
                 $run->launchDelayed($jenkins);
                 $this->log(sprintf('%s [%s] has been launched for user %s', $run->getJobName(), $run->getGitBranch(), $user->getUsername()));
             }
         } catch (Exception $e) {
             $msg = '{jk:daemon-launch-scheduled} : Une erreur est survenue : ' . $e->getMessage();
             // ecriture sur la sortie d'erreur
             file_put_contents('php://stderr', $msg);
             exit(1);
         }
         sleep($options['polling-delay']);
         if (time() - $start_time > $options['max-execution-time']) {
             exit(0);
         }
     }
 }
 /**
  *
  */
 public function preExecute()
 {
     $this->forward404Unless(Configuration::get('api_enabled', false), 'Api is disabled');
     $jenkinsFactory = new Jenkins_Factory();
     $jenkins = $jenkinsFactory->build($this->getJenkinsUrl());
     $this->setJenkins($jenkins);
     $this->setModelFactory(new modelFactory());
 }
 /**
  * Execute any application/business logic for this component.
  *
  * @param sfRequest $request The current sfRequest object
  *
  * @return mixed     A string containing the view name associated with this action
  */
 function execute($request)
 {
     $jenkinsFactory = new Jenkins_Factory();
     $availableJenkinsUrl = null;
     if ($this->getUser()->isAuthenticated()) {
         $jenkins = $jenkinsFactory->build($this->getUser()->getJenkinsUrl());
         $availableJenkinsUrl = $jenkins->isAvailable() ? $jenkins->getUrl() : null;
     }
     $nbJobDelayed = count(JenkinsRunPeer::getDelayed($this->getUser()));
     $menus = array('Dashboard' => array('url' => 'jenkins/index'), 'Create a build branch' => array('url' => 'jenkins/createGroupRun'), $nbJobDelayed => array('url' => 'jenkins/delayed', 'title' => 'See delayed list', 'class' => 'btn btn-primary btn-delayed', 'dropdown_class' => 'btn btn-primary btn-delayed-caret', 'dropdowns' => array('Launch all delayed jobs' => array('url' => 'jenkins/launchAllDelayed', 'title' => sprintf('Launch all delayed jobs (%s)', $nbJobDelayed)))));
     $activeLink = sprintf('%s/%s', $this->getContext()->getActionStack()->getFirstEntry()->getModuleName(), $this->getContext()->getActionStack()->getFirstEntry()->getActionName());
     $this->setVar('menus', $menus);
     $this->setVar('activeLink', $activeLink);
     $this->setVar('user', $this->getUser());
     $this->setVar('available_jenkins_url', $availableJenkinsUrl);
 }
 /**
  * @return void
  */
 public function preExecute()
 {
     if (null === $this->getJenkinsUrl()) {
         $this->getUser()->setFlash('error', "There is no url for your Jenkins");
         $this->redirect('user/configure');
     }
     $jenkinsFactory = new Jenkins_Factory();
     $jenkins = $jenkinsFactory->build($this->getJenkinsUrl());
     $this->setJenkins($jenkins);
     //à chaque hit on met à jour
     if ($jenkins->isAvailable()) {
         JenkinsRunPeer::fillEmptyJobBuildNumber($jenkins, $this->getUser()->getUserId());
     } else {
         $this->getUser()->setFlash('error', 'Jenkins is not started, or your configuration is incorrect.');
     }
     $this->setVar('jenkins', $jenkins);
 }