first commit
This commit is contained in:
33
subprocess.pl
Normal file
33
subprocess.pl
Normal file
@@ -0,0 +1,33 @@
|
||||
#! /usr/bin/env perl
|
||||
use Mojolicious::Lite;
|
||||
|
||||
get '/short_run' => sub {
|
||||
my $c = shift;
|
||||
app->log->debug("short_run: PID $$");
|
||||
$c->render(text => "Hello from short_run.\n");
|
||||
};
|
||||
|
||||
get '/long_run/:seconds' => sub {
|
||||
my $c = shift;
|
||||
my $seconds = $c->param('seconds') || 5;
|
||||
app->log->debug("long_run: PID $$");
|
||||
$c->render_later;
|
||||
my $subprocess = Mojo::IOLoop::Subprocess->new;
|
||||
$subprocess->run(
|
||||
sub {
|
||||
my $subprocess = shift;
|
||||
$c->app->log->debug("long_run1: PID $$");
|
||||
qx|sleep $seconds|;
|
||||
return $seconds;
|
||||
},
|
||||
sub {
|
||||
my ($subprocess, $err, $secs) = @_;
|
||||
$c->app->log->debug("long_run2: PID $$");
|
||||
$c->render(text => "Hello from long_run with $secs sec.\n");
|
||||
}
|
||||
);
|
||||
$subprocess->ioloop->start unless $subprocess->ioloop->is_running;
|
||||
};
|
||||
|
||||
app->inactivity_timeout(3600);
|
||||
app->start;
|
||||
Reference in New Issue
Block a user