79 lines
2.8 KiB
Perl
Raw Normal View History

package Hydra::Controller::Job;
use strict;
use warnings;
use base 'Hydra::Base::Controller::ListBuilds';
use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils;
sub job : Chained('/') PathPart('job') CaptureArgs(3) {
my ($self, $c, $projectName, $jobsetName, $jobName) = @_;
$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;
}
sub overview : Chained('job') PathPart('') Args(0) {
my ($self, $c) = @_;
my $job = $c->stash->{job};
$c->stash->{template} = 'job.tt';
2013-01-22 14:41:02 +01:00
$c->stash->{lastBuilds} =
[ $job->builds->search({ finished => 1 },
{ order_by => 'id DESC', rows => 10, columns => [@buildListColumns] }) ];
$c->stash->{queuedBuilds} = [
$job->builds->search(
{ finished => 0 },
2013-01-22 14:09:37 +01:00
{ join => ['project']
, order_by => ["priority DESC", "id"]
, '+select' => ['project.enabled']
2013-01-22 14:41:02 +01:00
, '+as' => ['enabled']
}
2013-01-22 14:09:37 +01:00
) ];
# If this is an aggregate job, then get its constituents.
my @constituents = $c->model('DB::Builds')->search(
{ aggregate => { -in => $job->builds->search({}, { columns => ["id"], order_by => "id desc", rows => 10 })->as_query } },
{ join => 'aggregateconstituents_constituents',
columns => ['id', 'job', 'finished', 'buildstatus'],
+select => ['aggregateconstituents_constituents.aggregate'],
+as => ['aggregate']
});
my $aggregates = {};
my %constituentJobs;
foreach my $b (@constituents) {
my $jobName = $b->get_column('job');
$aggregates->{$b->get_column('aggregate')}->{$jobName} =
{ id => $b->id, finished => $b->finished, buildstatus => $b->buildstatus};
$constituentJobs{$jobName} = 1;
}
$c->stash->{aggregates} = $aggregates;
$c->stash->{constituentJobs} = [sort (keys %constituentJobs)];
}
# 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;
$c->stash->{jobStatus} = $c->model('DB')->resultset('JobStatusForJob')
->search({}, {bind => [$c->stash->{project}->name, $c->stash->{jobset}->name, $c->stash->{job}->name]});
$c->stash->{allJobs} = $c->stash->{job_};
$c->stash->{latestSucceeded} = $c->model('DB')->resultset('LatestSucceededForJob')
->search({}, {bind => [$c->stash->{project}->name, $c->stash->{jobset}->name, $c->stash->{job}->name]});
$c->stash->{channelBaseName} =
2009-03-13 15:41:19 +00:00
$c->stash->{project}->name . "-" . $c->stash->{jobset}->name . "-" . $c->stash->{job}->name;
}
1;