Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel delayed jobs #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/front/modules/default/actions/topMenuComponent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function execute($request)
'url' => 'jenkins/launchAllDelayed',
'title' => sprintf('Launch all delayed jobs (%s)', $nbJobDelayed),
),
'Clean delayed jobs' => array(
'url' => 'jenkins/cleanAllDelayed',
'title' => sprintf('Clean all delayed jobs (%s)', $nbJobDelayed),
),
)
),
);
Expand Down
33 changes: 33 additions & 0 deletions apps/front/modules/jenkins/actions/cleanAllDelayedAction.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

class cleanAllDelayedAction extends baseJenkinsAction
{

/**
* @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());
$numDelayedJobs = count($runs);
foreach ($runs as $run)
{
$run->setLaunched(1);
$run->setJobBuildNumber(null);
$run->save();
$numDelayedJobs--;
}
if ($numDelayedJobs > 0)
{
$this->getUser()->setFlash('info', sprintf('[%d] delayed jobs have been deleted', $numDelayedJobs));
}
else
{
$this->getUser()->setFlash('info', 'All delayed jobs have been deleted');
}
$this->redirect('@homepage');
}

}
59 changes: 38 additions & 21 deletions apps/front/modules/jenkins/actions/delayedAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,51 @@ function execute($request)
$messages = array();
foreach ($form->getValue('runs') as $id => $datas)
{
$run = JenkinsRunPeer::retrieveByPK($id);
if ('on' !== $datas['launch_job'])
if ($request->getParameter('launch_delayed'))
{
$run->setLaunchDelayed(null);
$run->save();
continue;
}
//launch selected jobs
$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());
$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')
);
}
}
else
{
$run->setLaunchDelayed($launchAt);
//undelayed selected jobs
$run = JenkinsRunPeer::retrieveByPK($id);
$run->setLaunched(1);
$run->setJobBuildNumber(null);
$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')
'The job [%s] in build branch has been deleted from the list',
$run->getJobName(),
$run->getGitBranch()
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion apps/front/modules/jenkins/templates/delayedSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
</ol>
<?php endif; ?>
</div>
<?php if (count($form['runs']) > 0): ?>
<div class="form-footer">
<input type="submit" value="Launch" class="btn btn-large btn-primary"/>
<input type="submit" name="delete_delayed" value="Delete" class="btn btn-large btn-primary btn-delete"/>
<input type="submit" name="launch_delayed" value="Launch" class="btn btn-large btn-primary"/>
</div>
<?php endif; ?>
</form>


Expand Down