How can I execute code after rendering in Mojolicious?

一笑奈何 提交于 2021-02-10 03:04:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!