/** * @param sfRequest $request The current sfRequest object * * @return mixed A string containing the view name associated with this action */ function execute($request) { $runs = JenkinsRunPeer::getDelayed($this->getUser()); $form = new DelayedRunForm(array(), array('runs' => $runs)); $jenkins = $this->getJenkins(); if (sfRequest::POST === $request->getMethod()) { $form->bind($request->getParameter('delayed_run')); if ($form->isValid()) { $messages = array(); foreach ($form->getValue('runs') as $id => $datas) { $run = JenkinsRunPeer::retrieveByPK($id); if ('on' !== $datas['launch_job']) { $run->setLaunchDelayed(null); $run->save(); continue; } $launchAt = null; if (strlen($datas['scheduled_at']) > 0) { $launchAt = strtotime($datas['scheduled_at']); } if (null === $launchAt) { $run->launchDelayed($this->getJenkins()); $messages[] = sprintf('The job [%s] in build branch has been launched', $run->getJobName(), $run->getGitBranch()); } else { $run->setLaunchDelayed($launchAt); $run->save(); $messages[] = sprintf('The job [%s] in build %s branch will be launched at %s ', $run->getJobName(), $run->getGitBranch(), $run->getLaunchDelayed('Y-m-d H:i')); } } $this->getUser()->setFlash('info', $messages); $this->redirect('jenkins/index'); } } $delayedRuns = array(); $durationFormatter = new durationFormatter(); foreach ($runs as $run) { $groupRun = $run->getJenkinsGroupRun(); $parameters = $run->getParameters(); $build = $run->getJenkinsJob($jenkins)->getLastSuccessfulBuild($jenkins); $lastDuration = 0; if (null !== $build) { $lastDuration = $build->getDuration(); } $delayedRuns[$run->getId()] = array('group_run_label' => $groupRun->getLabel(), 'group_run_url' => $this->generateUrl('branch_view', $groupRun), 'group_run_result' => $groupRun->getResult($jenkins), 'last_duration' => $lastDuration, 'parameters' => null === $parameters ? $parameters : json_decode($run->getParameters(), true)); } $this->setVar('form', $form); $this->setVar('delayed_runs', $delayedRuns); $this->setVar('duration_formatter', $durationFormatter); }
/** * @param sfRequest $request The current sfRequest object * * @return mixed|void A string containing the view name associated with this action|void * @throws Exception */ function execute($request) { $jenkins = $this->getJenkins(); if ($request->hasParameter('group_run_id')) { $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('group_run_id')); $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('can\'t create JenkinsGroupRun with id %s', $request->getParameter('group_run_id'))); $jenkinsRuns = $jenkinsGroupRun->getJenkinsRuns(); foreach ($jenkinsRuns as $jenkinsRun) { $this->cancelJenkinsRun($jenkinsRun, $jenkins); } $this->getUser()->setFlash('info', sprintf('All builds of group [%s] have been canceled', $jenkinsGroupRun->getLabel())); $this->redirect($this->generateUrl('branch_view', $jenkinsGroupRun)); } elseif ($request->hasParameter('run_id')) { $jenkinsRun = JenkinsRunPeer::retrieveByPK($request->getParameter('run_id')); $this->forward404Unless($jenkinsRun instanceof JenkinsRun, sprintf('can\'t create JenkinsRun with id %s', $request->getParameter('run_id'))); $this->cancelJenkinsRun($jenkinsRun, $jenkins); $this->redirect($this->generateUrl('branch_view', $jenkinsRun->getJenkinsGroupRun())); } else { throw new Exception('run_id or group_run_id parameter is required'); } }