possibly dependant on how long your process takes, you could simplify
things by using "on 'finish'" to run your process after rendering a
response. Then same deal with recording progress to db etc..

sub refresh {
    my $self    = shift;

    $self->on(finish => sub{
        my $ctrl = shift;
        $total = $self->modules->nr_of_modules();
        ...
    });

    $self->render()
}




Jason Galea
lecstor.com
ezyapp.com

On Wed, Apr 1, 2015 at 9:44 PM, Jason Galea <[email protected]> wrote:

> Hi Johan,
>
> I don't think after_build_tx is what you want. It looks like that is for
> hooking into the request transaction and getting progress updates from it.
>
> I think you would want to background your process in some way (fork or job
> queue maybe.. minion?) and return your page response. The background
> process should then store it's progress periodically in a database or
> similar. From the page you then poll the server via ajax to another
> endpoint that can read and return the progress value and update the
> progress bar in the page.
>
> cheers,
>
> Jason
>
>
>
>
> Jason Galea
> lecstor.com
> ezyapp.com
>
> On Sat, Mar 28, 2015 at 11:23 PM, Johan De Graeve <[email protected]>
> wrote:
>
>> Hi everybody,
>>
>> Could somebody provide me please with a simple example to update a
>> (bootstrap) progress bar when performing a long lasting function.
>>
>> I read that maybe the after_build_tx hook is the answer to my questions.
>> Just not sure how to use is.
>>
>> after_build_tx <http://mojolicio.us/perldoc/Mojolicious#toc>
>>
>> Emitted right after the transaction is built and before the HTTP request
>> gets parsed.
>>
>> $app->hook(after_build_tx => sub {
>>   my ($tx, $app) = @_;
>>   ...});
>>
>> This is a very powerful hook and should not be used lightly, it makes
>> some rather advanced features such as upload *progress bars* possible.
>> Note that this hook will not work for embedded applications, because only
>> the host application gets to build transactions. (Passed the transaction
>> and application object)
>> I wrote a controller which a refresh function which takes quite a while
>>
>> sub refresh {
>>     my $self    = shift;
>>
>>     $total = $self->modules->nr_of_modules();
>>     foreach my $environment (@environments) {
>>         my @modules = $self->modules->modules_in_env($environment);
>>         foreach my $module (@modules) {
>>             $self->modules->add_module(environment => $environment,
>> module => $module);
>>             $done++;
>>             $progress = int($done / $total)*100;
>>             $self->render( progress => $progress );
>>         }
>>     }
>> }
>>
>> And would like to pass the $progress to my template and update the
>> progress bar.
>>
>>
>> <div class="progress">
>>   <div class="progress-bar" role="progressbar" aria-valuenow="<%= $progress 
>> =>" aria-valuemin="0" aria-valuemax="100" style="width: <%= $progress %>%;">
>>     <%= $progress %>%
>>   </div></div>
>>
>> All help will be very much appreciated.
>>
>> Thx,
>> Johan
>>
>>  --
>> 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.
>>
>
>

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