views:

197

answers:

3

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?

A: 

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

Stephan Wehner
Yes, it is possible solution.But for two-way communication with the spawned processthere may be something better than using the database.Thanks
taro
I guess you can set up a named pipe or other IPC id to communicate with the process, pass the name of that pipe (or its id) to the browser, and have the browser pass it back with the info that comes later. (Encrypt it/ Add crypt-signature).However, ordinarily web-apps run with several backends, which are on different hosts. So you probably need some path to reach the host running the process from the host serving the request with the info that comes later.If you don't like to use your database, how about you use memcache (which is a kind of database).Stephan
Stephan Wehner
A: 

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.

Larry K
A: 

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?

Greg