App-Mimosa
view release on metacpan or search on metacpan
lib/App/Mimosa/Controller/Root.pm view on Meta::CPAN
}
sub show_cached_report :Private {
my ( $self, $c ) = @_;
my $cached_report_file = $self->_temp_file( $c->stash->{job_id} . '.html' );
if (-e $cached_report_file) {
my $cached_report = slurp($cached_report_file);
$c->stash->{report} = $cached_report;
$c->stash->{template} = 'report.mason';
} else {
$c->stash->{error} = <<ERROR;
Could not find cached report file $cached_report_file !
ERROR
$c->detach('/error');
}
}
sub make_job_id :Private {
my ( $self, $c ) = @_;
my $sha1 = sha1_hex freeze {
params => $c->req->parameters,
uploads => $c->req->uploads,
#TODO: add the user - user => $c->user,
};
my $rs = $c->model('BCS')->resultset('Mimosa::Job');
my $jobs = $rs->search( { sha1 => $sha1 } );
if ($jobs->count == 0) { # not a duplicate job, proceed
my $job = $rs->create({
sha1 => $sha1,
user => $c->user_exists ? $c->user->get('username') : 'anonymous',
start_time => DateTime->now(),
});
$c->stash->{job_id} = $job->mimosa_job_id();
} else { # this is a duplicate, check if it is still running and notify user appropriately
my $job = $jobs->single;
my ($start,$end) = ($job->start_time, $job->end_time);
my $jid = $job->mimosa_job_id;
my $user = $job->user;
# TODO: add more info to the error message
if( $end ) { # already finished
$c->stash->{job_id} = $jid;
$c->detach('/show_cached_report');
} else {
$user ||= 'anonymous';
$c->stash->{error} = <<ERROR;
This job (# $jid) was started at $start by $user and is still running.
ERROR
}
$c->detach('/input_error');
}
}
=head2 default
Standard 404 error page
=cut
sub default :Path {
my ( $self, $c ) = @_;
$c->response->body( 'Nothing to see here' );
$c->response->status(404);
}
=head2 input_error
Standard page for user-input errors.
=cut
sub input_error :Private {
my ( $self, $c ) = @_;
$c->res->status( 400 );
$c->forward('error');
}
sub error :Private {
my ( $self, $c ) = @_;
$c->stash->{template} = 'error.mason';
$c->res->status( 500 ) if ! $c->res->status || $c->res->status == 200;
}
=head2 end
Attempt to render a view, if needed.
=cut
sub end : ActionClass('RenderView') {}
=head1 AUTHOR
Jonathan "Duke" Leto <jonathan@leto.net>
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__PACKAGE__->meta->make_immutable;
1;
( run in 2.058 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )