...an example of a very simple example...

oops, sorry about that :(

El miércoles, 16 de agosto de 2017, 14:57:36 (UTC-3), Daniel Mantovani 
escribió:
>
> Hi Franz, it could be a litle late but as an example of a very simple 
> example that I think should be very portable (at the expense of something 
> more efficent, like using message queues for instance), if your external 
> background process could report its advance atomically to a file like this 
> bash script for example:
>
> #!/bin/bash
> echo '...Starting background job' > status.data
> sleep 5
> echo '5 seconds gone...' > status.data
> sleep 2
> echo 'still working' > status.data
> sleep 3
> echo 'and finally...' > status.data
> sleep 1
> echo 'Finished' > status.data
>
>
> you should be able to consume this information from your mojolicious 
> applications just using a websocket and a recurring timer, like this for 
> example:
>
> use Mojolicious::Lite;
> use Mojo::File;
> use Mojo::IOLoop;
>
> my $path = Mojo::File->new('status.data');
> websocket '/status' => sub {
> my $c = shift;
> my $id = Mojo::IOLoop->recurring(
> 1 => sub {
> my $status = 'Script never run';
> $status = $path->slurp if -f "$path";
> $c->send({json => {msg => $status}})
> }
> );
> $c->on(finish => sub { Mojo::IOLoop->remove($id) });
> };
>
> get '/' => 'index';
>
> app->start;
> __DATA__
>
> @@ index.html.ep
> <!DOCTYPE html>
> <html>
> <head>
> <title>Echo</title>
> <script>
> var ws = new WebSocket('<%= url_for('status')->to_abs %>');
> ws.onmessage = function (event) {
> document.body.innerHTML = JSON.parse(event.data).msg;
> };
> </script>
> </head>
> <body> This should disappear in a while </body>
> </html>
>
>
>
> please let me know if something like this was what you were looking for
> BR,
> Daniel
>
> El jueves, 30 de junio de 2011, 7:49:32 (UTC-3), dotless-vienna escribió:
>>
>> I don't insist on using threads, I just want to have some background 
>> worker that doesn't block my mojolicious server and reports its progress.
>>
>> I'd really appreciate a short code sample that demonstrates the launch of 
>> that background worker and mojolicious instance within one perl script.
>>
>> - Franz
>>
>> 2011/6/30 Sebastian Riedel <[email protected]>
>>
>>> For a general purpose solution i would not suggest it (way too 
>>> expensive), but in this specific case it could work.
>>>
>>> --
>>> Sebastian Riedel
>>> http://mojolicio.us
>>> http://twitter.com/kraih
>>> http://blog.kraih.com
>>>
>>>
>>> Am Donnerstag, 30. Juni 2011 um 10:21 schrieb David Davis:
>>>
>>> > You can use Mojo::UserAgent in your subprocess to contact your parent 
>>> process. You could even use websocket...
>>> >
>>> > David Davis
>>> > ☄ Software Engineer
>>> > http://xant.us/
>>> > http://xantus.tel/
>>> >
>>> >
>>> > On Thu, Jun 30, 2011 at 00:46, Sebastian Riedel <[email protected] 
>>> (mailto:[email protected])> wrote:
>>> > >  Ultra portable makes it tricky, Perl has no real threads and two 
>>> way communication between forked processes in a portable way is almost 
>>> impossible without external help.
>>> > >
>>> > >  --
>>> > >  Sebastian Riedel
>>> > > http://mojolicio.us
>>> > > http://twitter.com/kraih
>>> > > http://blog.kraih.com
>>> > >
>>> > >
>>> > >  Am Donnerstag, 30. Juni 2011 um 09:39 schrieb dotless-vienna:
>>> > >
>>> > > > Hi,
>>> > > >
>>> > > > In my desktop web app, the user should be able to trigger a long
>>> > > > running directory indexing task in the browser with subsequent
>>> > > > progress information (e.g. "Indexing file xy") delivered via AJAX.
>>> > > >
>>> > > > In short, I want to have something like 
>>> http://webpy.org/cookbook/background.
>>> > > >
>>> > > > How can I achieve this in Mojolicious? (I don't want to use 
>>> external
>>> > > > messaging services like RabbitMQ, since this should be an ultra-
>>> > > > portable web app)
>>> > > >
>>> > > > Franz
>>> > > >
>>> > > > --
>>> > > > You received this message because you are subscribed to the Google 
>>> Groups "Mojolicious" group.
>>> > > > To post to this group, send email to [email protected] 
>>> (mailto:[email protected]) (mailto:[email protected]).
>>> > > > To unsubscribe from this group, send email to 
>>> [email protected] (mailto:
>>> mojolicious%[email protected]) (mailto:
>>> [email protected] (mailto:
>>> mojolicious%[email protected])).
>>> > > > For more options, visit this group at 
>>> http://groups.google.com/group/mojolicious?hl=en.
>>> > >
>>> > >
>>> > >  --
>>> > >  You received this message because you are subscribed to the Google 
>>> Groups "Mojolicious" group.
>>> > >  To post to this group, send email to [email protected] 
>>> (mailto:[email protected]).
>>> > >  To unsubscribe from this group, send email to 
>>> [email protected] (mailto:
>>> mojolicious%[email protected]).
>>> > >  For more options, visit this group at 
>>> http://groups.google.com/group/mojolicious?hl=en.
>>> >
>>> >  --
>>> >  You received this message because you are subscribed to the Google 
>>> Groups "Mojolicious" group.
>>> >  To post to this group, send email to [email protected] 
>>> (mailto:[email protected]).
>>> >  To unsubscribe from this group, send email to 
>>> [email protected] (mailto:
>>> [email protected]).
>>> >  For more options, visit this group at 
>>> http://groups.google.com/group/mojolicious?hl=en.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google 
>>> Groups "Mojolicious" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to 
>>> [email protected].
>>> For more options, visit this group at 
>>> http://groups.google.com/group/mojolicious?hl=en.
>>>
>>>
>>

-- 
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