Using a non-blocking API would be ideal but the other option is to run the
blocking call in a forked process using something like
https://metacpan.org/pod/Mojo::IOLoop::ForkCall . Either way the delay
helper is helpful for this:
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Synchronizing-events

On Tue, Jan 19, 2016 at 4:15 AM, Daniel Harper <[email protected]> wrote:

>
> Firstly I am new to Mojolicious so if what I am asking is stupid please
> forgive me.
>
> I am writing a web restful api connection to a asterisk based dialer. I
> want each client to have a unique socket connection to the asterisk AMI
> (actually to a asterisk AMI proxy but it behaves exactly like asterisk AMI)
> The app shouldn't block as requests can take up to 20-30 seconds to send
> back a response and multiple clients will be making requests at any one
> time.
>
> To create unique sockets I am using $self->session('id') to set cookie
> session id on the client browser. The api will be called via a jquery ajax
> call.
>
> So I am doing something like this ...
>
> get '/dial' => sub {
>
>         my $s = shift;
>         $s->render_later;
>         $s->render(json => {Response => "Error",Message => "No telnum"})
> if !defined $s->param('telnum');
>         $s->render(json => {Response => "Error",Message => "No agentid"})
> if !defined $s->param('agentid');
>
>         my %cmd=();
>         $cmd{Action} = 'Dial';
>         $cmd{Telnum} = $s->param('telnum');
>         $cmd{AgentID} = $s->param('agentid');
>         my %response = $sockets{$s->session('id')}->sendcommand(%cmd);
>         $s->render(json => {Response => $response{Response},Message =>
> $response{Message},SessionID => $s->session('id')});
>
> };
>
> Where  "sendcommand(%cmd);" sends a command using Asterisk::Manager to
> asterisk proxy which will dial a phone number. If this call is a noanswer
> it will take 20 seconds to return a response.
>
> (If I use the cpan module Asterisk::AMI I get the following error when
> using morbo "AnyEvent::CondVar: recursive blocking wait attempted at
> /home/dharper/perl5/perlbrew/perls/perl-5.20.2/lib/site_perl/5.20.2/Asterisk/AMI.pm
> line 1131." ? )
>
> It sort of all works expect my issue is that morbo is blocking so I can
> only make one request at a time otherwise they get queued up. I have tried
> hypnotoad and that works well but only has 5 workers by default. (this app
> will have 100-200 clients connecting at any one time)
>
> I was wondering if someone knows the best way to do this so so I can have
> multiple clients sending multiple (slow 20-30 second) requests via a
> socket. Perhaps I should be using IO::Socket or some-other direct socket
> module? or I should just up the hypnotoad workers to 200 and be done with
> it?
>
> Any help would be much appreciated.
>
> Thanks,
>
> Daniel
>
>
>
>
>
> --
> 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 https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to