The main intent of minion is to execute long running, blocking tasks that
would take longer than the life cycle of a request, so return values aren't
a feature.

Think of it as a fire and forget in terms of the initiating request, and
you can check the status of it in subsequent requests.


On Monday, January 26, 2015, Per Carlson <[email protected]> wrote:

> Hi.
>
> I'm thinking of using Minion as a job queue in an existing Mojolicious
> application. The concept of handing off a job to Minion is straight
> forward, but how to get the result back?
>
> Here's a small (not working) example application:
>
> #!/usr/bin/env perl
>
> use Mojolicious::Lite;
> use Net::Ping;
>
> plugin Minion => { File => "minion.db" };
>
> app->minion->add_task(ping => sub {
>   my ($job, $host) = @_;
>
>   my $p = Net::Ping->new;
>   $p->port_number(22);
>
>   if ($p->ping($host)) {
>     $job->finish("Host $host is alive");
>   } else {
>     $job->fail("Host $host doesn't respond");
>   }
>   return;
> });
>
> get '/ping/(:host)' => sub {
>   my $c = shift;
>
>   my $jobid = $c->minion->enqueue(
>     ping => [ $c->param('host') ]
>   );
>   $c->render_later;
>
>   # Register event handlers to get the result/error
>   # from Minion
>   my $job = $c->minion->job($jobid);
>
>   $job->on(error => sub {
>     my ($job, $err) = @_;
>     $c->render(status => 500, text => $err);
>   });
>
>   $job->on(finish => sub {
>     my ($job, $result) = @_;
>     $c->render(text => $result);
>   });
> };
>
> app->start;
>
> ​The above doesn't work at all. I suspect that's because the worker is
> running in another process than the app, and doesn't share the same event
> scopes.
>
> Is there another (working) way to retrieve the result in the same route​?
>
> --
> Pelle
>
> Research is what I'm doing when I don't know what I'm doing.
> - Wernher von Braun
>
> --
> 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]
> <javascript:_e(%7B%7D,'cvml','mojolicious%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> Visit this group at http://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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to