开发者

Queuing in tandem with a Ruby Web socket server

开发者 https://www.devze.com 2023-04-12 07:11 出处:网络
I am writing an application using jruby on rails开发者_Python百科.Part of the application initiates a long running process from a web page.The long running process could last for 20 minutes in some ca

I am writing an application using jruby on rails开发者_Python百科. Part of the application initiates a long running process from a web page. The long running process could last for 20 minutes in some cases but will in most cases outlive a web page response in terms of time. I also want the job to continue if the user closes down the browser. The long running process will add records to a database as it is running.

I want to give visual indications of the inserts into the database on the web page and I would prefer to use web sockets rather than polling the database for the inserts.

I am thinking of sending a message to a resque queue with a queue handler that will ensure the job is completed if the user closes down the browser. The queue handler will perform the inserts into the database.

I was thinking of using EM-WebSocket as my websocket server.

The problem I have is:

How can I communicate between the resque process and EM-WebSocket process? I want to somehow pass the details of the new inserts into the database from the resque process to an EM-WebSocket instance that will communicate with the browser?

Anybody solved a problem like this or any ideas how I can do this?


I'm actually working on a gem that makes this pretty simple. Right now it's pretty bare, but it does work. https://github.com/KellyMahan/RealTimeRails

It runs an event-machine server for listening for updates and makes use of em-websockets to send those updates to the browser.

It's meant to watch for active record updates through an after_save call that tells the event-machine server it has an update for it's model with an id. Then it matches the model and id to specific channels to send a message to connections on the web socket server. When the browser receives a notice to update it makes an ajax call to retrieve the latest results.

Still a work in progress but it could help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号