In a Mojolicious app, I'm trying to convert ODT files into HTML when a link is clicked. I convert the files by using "soffice", a shell command. Converting the files takes some time. I send status messages to the user to notify him of the progress. I send those status update messages by writing to a Mojo::Log object. Then, I subscribe to this log object in an EventSource route.
Then I loop through the files and use AnyEvent::Util run_cmd to execute the external "soffice" program.
for my $file (@{ $filelist }) {
my $output_dir = './output_dir';
my $cmd = "soffice --headless --convert-to html --outdir '$output_dir' '$file'";
my $cv = AnyEvent->condvar;
my $w;
$w = run_cmd($cmd,
'>' => sub { my $out = shift;
&WriteToLog({ status => "cmd output '$out'..." });
undef $w;
$cv->send;
},
'2>' => sub { my $err = shift;
&WriteToLog({ status => "ERROR '$err'..." });
undef $w;
$cv->send;
}
);
$cv->recv;
}
Pretty much copied and pasted from the main AnyEvent tutorials. If there are only few files to convert (around 2 or 3), then all goes well. The status messages sent through the EventSource connection appears on the client browser. Then after all the files have been converted, the web page is rendered.
If more files are to be processed, a few files get converted then the error message in the thread title occurs.
The routing for the route containing the code above is this:
my $initdocs = $r->under->to('docroute#initdocs');
$initdocs->get('/showdocs')->to('docroute#showdocs');
The code above is in the "initdocs" route.
Any help is appreciated. Thanks in advance.