Skip to content

Commit

Permalink
Merge pull request #36 from Kitware/autoremove_jobs
Browse files Browse the repository at this point in the history
Autoremove jobs
  • Loading branch information
zackgalbreath committed Mar 30, 2015
2 parents fad1cf8 + b4b7866 commit 2f35c8a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cdash/autoremove.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,44 @@ function removeFirstBuilds($projectid, $days, $maxbuilds, $force=false)
add_log($s, 'removeFirstBuilds');
print " -- " . $s . "\n"; // for "interactive" command line feedback
remove_build($buildids);

// Remove any job schedules that are older than our cutoff date
// and not due to repeat again.
require_once('models/constants.php');
require_once('models/clientjobschedule.php');
$sql =
"SELECT scheduleid FROM client_job AS cj
LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id
WHERE cj.status > ". CDASH_JOB_RUNNING . "
AND cjs.projectid=$projectid AND cj.startdate < '$startdate'
AND (cjs.repeattime = 0.00 OR
(cjs.enddate < '$startdate' AND cjs.enddate != '1980-01-01 00:00:00'))";

$job_schedules = pdo_query($sql);
while($job_schedule = pdo_fetch_array($job_schedules))
{
$ClientJobSchedule = new ClientJobSchedule();
$ClientJobSchedule->Id = $job_schedule['scheduleid'];
$ClientJobSchedule->Remove();
}

// Remove any jobs that are older than our cutoff date.
// This occurs when a job schedule is set to continue repeating, but
// some of its past runs are older than our autoremove threshold.
require_once('models/clientjob.php');
$sql =
"SELECT cj.id FROM client_job AS cj
LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id
WHERE cj.status > ". CDASH_JOB_RUNNING . "
AND cjs.projectid=$projectid AND cj.startdate < '$startdate'";

$jobs = pdo_query($sql);
while($job = pdo_fetch_array($jobs))
{
$ClientJob = new ClientJob();
$ClientJob->Id = $job['id'];
$ClientJob->Remove();
}
}

?>
12 changes: 12 additions & 0 deletions models/clientjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ function Save()
add_last_sql_error("ClientJob::Save");
} // end Save

/** Remove a job */
function Remove()
{
if(!$this->Id)
{
add_log("ClientJob::Remove","Id not set");
return;
}
pdo_query("DELETE FROM client_job WHERE id=".qnum($this->Id));
add_last_sql_error("ClientJob::Remove");
} // end Remove

} // end class proJob

0 comments on commit 2f35c8a

Please sign in to comment.