Question

I'm making a Rails application. In the one action I need to spawn a long running process. This is not a problem. I can fork new process using spawn gem or some other. But some time after process has been spawned, user must be able to pass additional data to that process.

Sure, I can fork process which will listen a UNIX socket, store socket address in the HTTP session and communicate with that process using drb protocol when user will require to pass new data to process. But I think it is not best solution and it will be a problem to deploy an application to the hosting.

What is the easy way to do that?

Was it helpful?

Solution

Can the additional data go into the database, and the process checks there for the "new data"?

OTHER TIPS

I suggest going up-level. Use delayed_job to handle the spawning and initial setting of parameters for your job.

You can modify delayed_job's dbms model to add fields for the additional information that you want to later send to the job.

Then your flow would be:

  1. Submit using delayed_job. Store the id of the jobs table. If stock de;ayed_job doesn't give you the job id, then modify delayed_job as necessary.

  2. Add the additional data to the field in the jobs table

If your main job needs data back from the forked job, then you could also have a db fields for that.

You should try to design your application to mimimize the amount of message passing needed. Otherwise you'll need to design a message protocol. Can be done, but it is work that you should try to avoid.

Can't you use a thread and communicate with it via two queues, one for input to the thread, and one for the thread's responses?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top