The behavior of Mojo::Server::Daemon and Morbo

239 views
Skip to first unread message

Andrey Khozov

unread,
Aug 27, 2013, 12:51:28 AM8/27/13
to mojol...@googlegroups.com
Hello!

I have an example of a small Mojolicious::Lite and Mango application that works correctly under Mojo::Server::Daemon and does not work under Morbo.

Code (https://gist.github.com/avkhozov/6338504):


#!/usr/bin/perl

use Data::Dumper;
use Mango;

use Mojolicious::Lite;

my $mango = Mango->new;
my $db = $mango->db('test');

get '/' => sub {
my $self = shift;
$self->render_later;

Mojo::IOLoop->delay(
sub {
Mojo::IOLoop->timer(1 => shift->begin);
},
sub {
$db->stats(shift->begin);
},
sub {
my ($delay, $err, $stats) = @_;
return $self->render(text => $err) if $err;
$self->render(text => Dumper $stats);
}
);
};

app->start;

Output:

$ morbo app.pl
[Tue Aug 27 10:38:37 2013] [info] Listening at "http://*:3000".
Server available at http://127.0.0.1:3000.
[Tue Aug 27 10:38:42 2013] [debug] Your secret passphrase needs to be changed!!!
[Tue Aug 27 10:38:42 2013] [debug] GET "/".
[Tue Aug 27 10:38:42 2013] [debug] Routing to a callback.
Timer a0c7e5ece3b89efbd336ea3a2b08a17c failed: Can't call method "protocol" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/Mango/Database.pm line 42.
[Tue Aug 27 10:38:57 2013] [debug] Inactivity timeout.


$ perl app.pl daemon
[Tue Aug 27 10:39:26 2013] [info] Listening at "http://*:3000".
Server available at http://127.0.0.1:3000.
[Tue Aug 27 10:39:28 2013] [debug] Your secret passphrase needs to be changed!!!
[Tue Aug 27 10:39:28 2013] [debug] GET "/".
[Tue Aug 27 10:39:28 2013] [debug] Routing to a callback.
[Tue Aug 27 10:39:29 2013] [debug] 200 OK (1.003680s, 0.996/s).



Software:

$ cpanm Mango
Mango is up to date. (0.12)
$ mojo version
CORE
  Perl        (v5.16.3, linux)
  Mojolicious (4.27, Top Hat)

OPTIONAL
  EV 4.0+               (4.15)
  IO::Socket::IP 0.16+  (0.21)
  IO::Socket::SSL 1.75+ (1.87)


As far as I know morbo only restarts Mojo::Server::Daemon when changes to files in certain directories.

Can anyone help me explain the behavior of the application under different servers?

-- 
Andrey Khozov

sri

unread,
Aug 27, 2013, 8:12:22 AM8/27/13
to mojol...@googlegroups.com, avkh...@googlemail.com
Can anyone help me explain the behavior of the application under different servers?

$mango is garbage collected before the first request, since under Morbo app->start doesn't block but return the application instance.

--
sebastian

Andrey Khozov

unread,
Aug 27, 2013, 12:40:29 PM8/27/13
to sri, mojol...@googlegroups.com
Thank you for the explanation.
--
Andrey Khozov
Reply all
Reply to author
Forward
0 new messages