Allow a redirect to be sent to the user that cannot be calculated when creating the Fork object. This is useful for Forks that build files to be downloaded.
This commit is contained in:
parent
22bf6e8451
commit
63c31404c2
4 changed files with 32 additions and 3 deletions
|
|
@ -32,6 +32,7 @@ my $session = start(); # this line required
|
|||
|
||||
# upgrade functions go here
|
||||
addPALastLogTable($session);
|
||||
addForkRedirect($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
|
@ -55,6 +56,18 @@ EOSQL
|
|||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Describe what our function does
|
||||
sub addForkRedirect {
|
||||
my $session = shift;
|
||||
print "\tAdd a column to Fork to keep track of late generated redirect URLs... " unless $quiet;
|
||||
# and here's our code
|
||||
$session->db->write(<<EOSQL);
|
||||
ALTER TABLE Fork add column redirect CHAR(255);
|
||||
EOSQL
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Describe what our function does
|
||||
#sub exampleFunction {
|
||||
|
|
|
|||
|
|
@ -278,6 +278,7 @@ sub finish {
|
|||
$props{latch} = 0;
|
||||
}
|
||||
$props{endTime} = time();
|
||||
$props{redirect} = $self->{redirect};
|
||||
$self->set( \%props );
|
||||
}
|
||||
|
||||
|
|
@ -514,6 +515,20 @@ sub setGroup {
|
|||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 setRedirect($url)
|
||||
|
||||
Allows a redirect to be set for the process after the initial fork. This happens
|
||||
in the case when a file is to be downloaded after the fork finishes.
|
||||
|
||||
=cut
|
||||
|
||||
sub setRedirect {
|
||||
my ( $self, $url ) = @_;
|
||||
$self->{redirect} = $url;
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 request ($module, $subname, $data)
|
||||
|
||||
Internal method. Generates a hashref suitable for passing to runRequest.
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ See the synopsis for what kind of response this generates.
|
|||
sub handler {
|
||||
my $process = shift;
|
||||
my $status = $process->getStatus;
|
||||
my ( $finished, $startTime, $endTime, $error ) = $process->get( 'finished', 'startTime', 'endTime', 'error' );
|
||||
my ( $finished, $startTime, $endTime, $error, $redirect ) = $process->get( qw/finished startTime endTime error redirect/ );
|
||||
|
||||
$endTime = time() unless $finished;
|
||||
|
||||
|
|
@ -76,7 +76,8 @@ sub handler {
|
|||
elapsed => ( $endTime - $startTime ),
|
||||
finished => ( $finished ? \1 : \0 ),
|
||||
);
|
||||
$status{error} = $error if $finished;
|
||||
$status{error} = $error if $finished;
|
||||
$status{redirect} = $redirect if $finished;
|
||||
$process->session->http->setMimeType('text/plain');
|
||||
JSON::encode_json( \%status );
|
||||
} ## end sub handler
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
args.first();
|
||||
}
|
||||
if (data.finished) {
|
||||
args.finish();
|
||||
args.finish(data);
|
||||
}
|
||||
else {
|
||||
setTimeout(fetch, args.interval || 1000);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue