From Dancer launch Background Process
Hello I would like to launch in background a perl program ( or function who create lot of PDF) from my Dancer APP. and view in web page the log of this program. I've done a small test, ajax part works well, but if my process backgroup is too long with sleep , nothing works, web browser wait... What is the best way to do that ? use backtick ``, system, exec ? create sub or launch external perl program as my $output = qx|perl /util/generation.pl $id &|; print $output; or fork module ? thanks for your advice Hugues. post '/generationpdf' => sub { ... ... background(); } #my test background process sub background { open (LOG,">:encoding(UTF-8)",$PATHPDF."generationpdf.log") || die ("Problème d'ouverture du fichier de log $!"); say LOG "\n################################################"; for (my $i=0;$i<300;$i++) { # sleep 1; say LOG $i; } } AJAX PART ajax '/getloadavg' => sub { my $cmd = "tail ". $PATHPDF. "generationpdf.log"; { timestamp => time, loadavg => `$cmd`, }; TEMPLATE PART <pre>Calcul des PDF: <span id="flog"></span> </pre> <script type="text/javascript"> setInterval(function() { $.getJSON('[% request.uri_base %]/getloadavg', function(response) { var point = [ response.timestamp, response.log ];; $("#timestamp").text(response.timestamp); $("#flog").text(response.flog); }) }, 1000); </script>
On 13-04-30 03:09 AM, Hugues Max wrote:
I would like to launch in background a perl program ( or function who create lot of PDF) from my Dancer APP. and view in web page the log of this program.
I've done a small test, ajax part works well, but if my process backgroup is too long with sleep , nothing works, web browser wait...
What is the best way to do that ?
Maybe something like Dancer::Plugin::GearmanXS to send the long-running job to a Gearman instance, and then have your browser either refresh the page until the job is done or, if you really feel space-age, have a websocket connection (see Dancer::Plugin::WebSocket) to the server to push the results to the client when it's ready? Joy, `/anick
participants (2)
-
Hugues Max -
Yanick Champoux