问题
I have some long running code that I'd like to execute after rendering in a Mojolicious app.
I'd like to avoid using Minion queues as I'd be calling many very short processes, and I've looked into Mojolicious::Plugin::ForkCall and Mojolicious::Plugin::Subprocess but they both timeout (as the short processes get called many times).
I remember coming across an example of this somewhere but cannot find it anymore.
Any help?
回答1:
Call fork
in an after_dispatch hook?
$app->hook(after_dispatch => sub {
my $c = shift;
my $pid = fork();
if (defined($pid) && $pid == 0) {
doSlowStuff();
exit;
}
});
来源:https://stackoverflow.com/questions/48092089/how-can-i-execute-code-after-rendering-in-mojolicious