Custom threadpools in Phusion Passenger

13 weergaven
Naar het eerste ongelezen bericht

Arindam Mukherjee

ongelezen,
2 sep 2016, 01:41:5602-09-2016
aan Phusion Passenger Discussions
I want to use a custom thread-pool within my RoR application for running some background jobs. I am not keen on using existing delayed jobs implementation.

I this risky using Phusion Passenger open-source version. Could the passenger process get reaped while a background task is running in the thread pool? If so, is there a way to get around it?

Regards,
Arindam

Daniel Knoppel

ongelezen,
2 sep 2016, 06:27:4102-09-2016
aan Phusion Passenger Discussions

Arindam Mukherjee

ongelezen,
2 sep 2016, 15:57:1502-09-2016
aan Phusion Passenger Discussions
Thanks. A few questions below.


On Friday, 2 September 2016 15:57:41 UTC+5:30, Daniel Knoppel wrote:

So to summarize:

1. In the controller that needs to initiate the background task, we should do the following before rendering the view:

response.headers["!~Request-OOB-Work"] = "true"

2. I must initiate my background task in the callback for an oob_work event.

Q1. Does the oob_work callback run in its own thread? Can I spawn a thread in the callback and do my actual processing in that thread?
Q2. The specific task I need to run would only be known in the controller that processes my request, not in the application initializer. Can I call on_event inside a controller, or do I have to always call it in the application initialization code - in which case its value is diminished.

Regards.
 

Arindam Mukherjee

ongelezen,
3 sep 2016, 00:32:5803-09-2016
aan Phusion Passenger Discussions
I noticed that no thread is created by Phusion to service the oob_work. But the rest of my questions remain.

Camden Narzt

ongelezen,
9 sep 2016, 16:00:0909-09-2016
aan Phusion Passenger Discussions
You are simply setting up a callback in the application initialization code, the handler is not called at that point. Passenger may call on_event for you, sometime after you set a !~Request-OOB-Work header, you don't call on_event yourself.

What you likely would need to do is setup a queue where you can specify from the controller the work you need done, then output the header, and in the oob work callback (the on_event function) you could check if the queue has work for you to do, and if so pop the task off the queue and perform that work.

However at that point you are basically starting to reimplement active_job http://edgeguides.rubyonrails.org/active_job_basics.html#creating-a-job
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten