Re: [Mojolicious] Minion: getting data out.

2019-10-22 Thread Justin Hawkins


> On 22 Oct 2019, at 12:31 am, BobbyBrown  wrote:
> 
> I still have not figured out how to reliably get data out of a minion task, 
> I'll have to work on events and read up on non-blocking.
> If I understand the code correctly the linkcheck example simply fails if the 
> minion job has not finished when it looks up the result?

The minion job is completely independent of your web request - which is the 
entire point.

If you are doing something which you expect to be completed in the time of the 
request, then you may as well just execute it immediately and block waiting for 
it (or look at Mojo::IOLoop::Subprocess).

Otherwise, you would check back on the minion job later, perhaps via a REST 
request or similar.

A typical flow:

* request causes minion job to be enqueued
* job id is returned to the user's browser
* user's browser starts polling a REST endpoint looking for job completion (via 
javascript)
* once the job is complete, the browser redirects to a new URL with the job data

This is far from the only way to do it, and javascript is not a requirement.

Cheers,

Justin

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/FC37D777-C462-49D8-B64E-F6A4504674B3%40hawkins.id.au.


Re: [Mojolicious] Minion: getting data out.

2019-10-21 Thread Sebastian Riedel
>   state=> "inactive",
>
>   "state" => "finished",

Look at the different states, the job is simply not finished yet at the time.

-- 
Sebastian Riedel
https://mojolicious.org
https://github.com/kraih
https://twitter.com/kraih

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CANn9nhEZ5GNLb9dcOwTsszFKCr_%3D01AhYUD3LoBMK-MVHJZ8uQ%40mail.gmail.com.


[Mojolicious] Minion: getting data out.

2019-10-21 Thread BobbyBrown
Hello all,

I am having a problem that I don't understand. I've got the following 
minion task in a helper in a plugin:

  $app->minion->add_task( passtest => sub { 

my ( $job, $aa, $bb ) = @_; 

my $cc = "$aa $bb"; 

$job->note( cc => "$cc" ); 
 
$job->finish("All went well!, $cc");   
 
  } );


I call it from the controller thus:
Saisissez le code i  my $id2 = $c->minion->enqueue( passtest => [ "bla", 
"url" ] );
  my $job = $c->minion->job("$id2");   
 
  say "New Method : " . pp($job->info);

But the output shows :


New Method : {
  args => ["bla", "url"],
  attempts => 1,
  children => [],
  created  => 1571654552.89089,
  delayed  => 1571654552.89089,
  finished => undef,
  id   => 195520,
  notes=> {},
  parents  => [],
  priority => 0,
  queue=> "default",
  result   => undef,
  retried  => undef,
  retries  => 0,
  started  => undef,
  state=> "inactive",
  task => "passtest",
  time => 1571654552.89342,
  worker   => undef,
}

No data has been caught. The strange thing is that from the minion admin I 
can see the data:
Saisissez le code ici...{
  "args" => [
"bla",
"url"
  ],
  "attempts" => 1,
  "children" => [],
  "created" => "2019-10-21T10:42:32.89089Z",
  "delayed" => "2019-10-21T10:42:32.89089Z",
  "finished" => "2019-10-21T10:42:32.90722Z",
  "id" => 195520,
  "notes" => {
"cc" => "bla url"
  },
  "parents" => [],
  "priority" => 0,
  "queue" => "default",
  "result" => "All went well!, bla url",
  "retried" => undef,
  "retries" => 0,
  "started" => "2019-10-21T10:42:32.89251Z",
  "state" => "finished",
  "task" => "passtest",
  "time" => "2019-10-21T10:45:09.66926Z",
  "worker" => 134
}

This is the point when I decide to ask for help. I've tried to pass hash 
referenced to the minion task as well, but they were not changed outside of 
the scope of the task, unlike in a subroutine. What should I be reading up 
on to better understand what is going on in such cases?

Kind regards,

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/664ae593-b7e2-416a-8780-9d1416322da5%40googlegroups.com.