$ cat myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
use Test::More;
use Test::Mojo;
use Minion;
app->plugin(Minion => {Mango => 'mongodb://localhost:27017/test'});
app->minion->add_task(t1 => sub {
my $job = shift;
$job->app->ua->request_timeout(1);
my $tx = $job->app->ua->get('/test');
warn $tx->success ? $tx->res->code : $tx->error->{message};
$job->finish;
});
sub func1 {
my ($app, $cb) = @_;
$app->delay(sub { shift->pass }, sub { $cb->() });
}
sub func2 {
my ($app, $cb) = @_;
$app->delay(sub { shift->pass }, sub { $cb->() });
}
get '/test' => sub {
my $c = shift;
$c->render_later;
func1($c->app, sub {
func2($c->app, sub {
$c->render(text => 'data');
});
});
};
get '/enqueue' => sub {
my $c = shift;
$c->render_later;
$c->minion->enqueue(t1 => [] => sub {
$c->rendered(200);
});
};
app->start;
my $t = Test::Mojo->new;
$t->get_ok('/enqueue');
$t->app->minion->perform_jobs;
done_testing;
$ MOJO_USERAGENT_DEBUG=1 MOJO_LOG_LEVEL=debug MOJO_IOLOOP_DEBUG=1 prove
myapp.pl
myapp.pl .. -- Reactor initialized (Mojo::Reactor::Poll)
[Wed Aug 27 21:59:01 2014] [debug] Your secret passphrase needs to be
changed!!!
-- Blocking request (/enqueue)
-- Connect (http:localhost:55948)
-- Client >>> Server (http://localhost:55948/enqueue)
GET /enqueue HTTP/1.1
Accept-Encoding: gzip
Host: localhost:55948
Connection: keep-alive
User-Agent: Mojolicious (Perl)
Content-Length: 0
[Wed Aug 27 21:59:01 2014] [debug] GET "/enqueue".
[Wed Aug 27 21:59:01 2014] [debug] Routing to a callback.
[Wed Aug 27 21:59:01 2014] [debug] Nothing has been rendered, expecting
delayed response.
[Wed Aug 27 21:59:01 2014] [debug] 200 OK (0.003049s, 327.976/s).
-- Client <<< Server (http://localhost:55948/enqueue)
HTTP/1.1 200 OK
Connection: keep-alive
Date: Wed, 27 Aug 2014 15:59:01 GMT
Content-Length: 0
Server: Mojolicious (Perl)
myapp.pl .. 1/? -- Reactor initialized (Mojo::Reactor::EV)
[Wed Aug 27 21:59:01 2014] [debug] Performing job "t1"
(53fe00457bb42c3a99010000:15004).
-- Blocking request (/test)
-- Reactor initialized (Mojo::Reactor::EV)
-- Connect (http:localhost:57116)
-- Client >>> Server (http://localhost:57116/test)
GET /test HTTP/1.1
Accept-Encoding: gzip
User-Agent: Mojolicious (Perl)
Connection: keep-alive
Host: localhost:57116
Content-Length: 0
[Wed Aug 27 21:59:01 2014] [debug] GET "/test".
[Wed Aug 27 21:59:01 2014] [debug] Routing to a callback.
[Wed Aug 27 21:59:01 2014] [debug] Nothing has been rendered, expecting
delayed response.
Request timeout at myapp.pl line 14.
myapp.pl .. ok
All tests successful.
Files=1, Tests=1, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.25 cusr 0.02
csys = 0.29 CPU)
Result: PASS
$
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.