2009-03-04 17:24:08 +00:00
|
|
|
package Hydra::Controller::Job;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use base 'Hydra::Base::Controller::ListBuilds';
|
|
|
|
use Hydra::Helper::Nix;
|
|
|
|
use Hydra::Helper::CatalystUtils;
|
|
|
|
|
|
|
|
|
2009-03-12 23:46:17 +00:00
|
|
|
sub job : Chained('/') PathPart('job') CaptureArgs(3) {
|
|
|
|
my ($self, $c, $projectName, $jobsetName, $jobName) = @_;
|
|
|
|
|
2009-04-08 22:08:00 +00:00
|
|
|
$c->stash->{job_} = $c->model('DB::Jobs')->search({project => $projectName, jobset => $jobsetName, name => $jobName});
|
|
|
|
$c->stash->{job} = $c->stash->{job_}->single
|
2009-03-13 15:41:19 +00:00
|
|
|
or notFound($c, "Job $projectName:$jobsetName:$jobName doesn't exist.");
|
|
|
|
$c->stash->{project} = $c->stash->{job}->project;
|
|
|
|
$c->stash->{jobset} = $c->stash->{job}->jobset;
|
2009-03-04 17:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 16:15:57 +00:00
|
|
|
sub overview : Chained('job') PathPart('') Args(0) {
|
|
|
|
my ($self, $c) = @_;
|
2013-08-26 18:58:04 +02:00
|
|
|
my $job = $c->stash->{job};
|
2009-04-02 16:15:57 +00:00
|
|
|
|
|
|
|
$c->stash->{template} = 'job.tt';
|
|
|
|
|
2013-01-22 14:41:02 +01:00
|
|
|
$c->stash->{lastBuilds} =
|
2013-08-26 18:58:04 +02:00
|
|
|
[ $job->builds->search({ finished => 1 },
|
2013-05-23 10:45:49 -04:00
|
|
|
{ order_by => 'id DESC', rows => 10, columns => [@buildListColumns] }) ];
|
2010-04-23 08:17:15 +00:00
|
|
|
|
2013-02-22 12:51:00 +01:00
|
|
|
$c->stash->{queuedBuilds} = [
|
2013-08-26 18:58:04 +02:00
|
|
|
$job->builds->search(
|
2013-02-22 12:51:00 +01:00
|
|
|
{ finished => 0 },
|
2013-10-11 12:01:52 +02:00
|
|
|
{ order_by => ["priority DESC", "id"] }
|
2013-01-22 14:09:37 +01:00
|
|
|
) ];
|
2013-08-26 18:58:04 +02:00
|
|
|
|
|
|
|
# If this is an aggregate job, then get its constituents.
|
|
|
|
my @constituents = $c->model('DB::Builds')->search(
|
2013-10-03 15:00:28 +02:00
|
|
|
{ aggregate => { -in => $job->builds->search({}, { columns => ["id"], order_by => "id desc", rows => 15 })->as_query } },
|
|
|
|
{ join => 'aggregateconstituents_constituents',
|
|
|
|
columns => ['id', 'job', 'finished', 'buildstatus'],
|
|
|
|
+select => ['aggregateconstituents_constituents.aggregate'],
|
|
|
|
+as => ['aggregate']
|
|
|
|
});
|
2013-08-26 18:58:04 +02:00
|
|
|
|
|
|
|
my $aggregates = {};
|
|
|
|
my %constituentJobs;
|
|
|
|
foreach my $b (@constituents) {
|
2013-10-03 15:00:28 +02:00
|
|
|
my $jobName = $b->get_column('job');
|
|
|
|
$aggregates->{$b->get_column('aggregate')}->{constituents}->{$jobName} =
|
|
|
|
{ id => $b->id, finished => $b->finished, buildstatus => $b->buildstatus };
|
|
|
|
$constituentJobs{$jobName} = 1;
|
2013-08-26 18:58:04 +02:00
|
|
|
}
|
|
|
|
|
2013-08-27 13:45:27 +00:00
|
|
|
foreach my $agg (keys %$aggregates) {
|
2013-10-03 15:00:28 +02:00
|
|
|
# FIXME: could be done in one query.
|
|
|
|
$aggregates->{$agg}->{build} =
|
|
|
|
$c->model('DB::Builds')->find({id => $agg}, {columns => [@buildListColumns]}) or die;
|
2013-08-27 13:45:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 18:58:04 +02:00
|
|
|
$c->stash->{aggregates} = $aggregates;
|
|
|
|
$c->stash->{constituentJobs} = [sort (keys %constituentJobs)];
|
2009-04-02 16:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-04 17:24:08 +00:00
|
|
|
# Hydra::Base::Controller::ListBuilds needs this.
|
|
|
|
sub get_builds : Chained('job') PathPart('') CaptureArgs(0) {
|
|
|
|
my ($self, $c) = @_;
|
2009-03-13 15:41:19 +00:00
|
|
|
$c->stash->{allBuilds} = $c->stash->{job}->builds;
|
2009-04-03 15:37:21 +00:00
|
|
|
$c->stash->{latestSucceeded} = $c->model('DB')->resultset('LatestSucceededForJob')
|
|
|
|
->search({}, {bind => [$c->stash->{project}->name, $c->stash->{jobset}->name, $c->stash->{job}->name]});
|
2009-03-04 17:24:08 +00:00
|
|
|
$c->stash->{channelBaseName} =
|
2009-03-13 15:41:19 +00:00
|
|
|
$c->stash->{project}->name . "-" . $c->stash->{jobset}->name . "-" . $c->stash->{job}->name;
|
2009-03-04 17:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|