I have a simple Plack app (something like Plack::App::GitHub::WebHook) that I run using plackup
. I perform a lengthy operation in the request handler, which currently makes the app unresponsive to subsequent requests until the operation is finished. How can I perform the operation in background, without blocking other requests? And a follow-up question, how can I keep at most one job running in that background queue?
I’m used to libdispatch, so I’d love something like this:
my $queue = Hypothetical::Concurrency::Queue->new(max_jobs => 1);
$queue->dispatch(sub {
# code
});
I have just realized there’s one very important distinction I forgot to make: I don’t have to wait for the job to finish to respond to the HTTP request. Which means I’m fine with Forks::Super:
Now servicing the request finishes immediately, the long operation runs in background and there’s always at most one of them running.
Forks::Super
looks complex and takes ages to install, so I’d be happy if someone knows a more lightweight module offering a similar feature.