开发者

Are there any Rails Plugins that use JS to poll the server for completion of a background process?

开发者 https://www.devze.com 2022-12-26 07:42 出处:网络
I know it开发者_开发百科 might be simple to write some polling JS that asks the Rails application if it has completed a background job. But I wonder if anyone has already packaged up this functionalit

I know it开发者_开发百科 might be simple to write some polling JS that asks the Rails application if it has completed a background job. But I wonder if anyone has already packaged up this functionality as a plugin.

Basically, I have a few delayed_jobs running, and am looking for a plugin that will poll the server for completion of a particular job, then activate a callback when it finds that the job is complete.

Any ideas anyone?

Berns


There are probably few plugins that do this because it's often a very application-specific solution, especially on the server-side. It's easy enough to build, with a Rails action returning the status of the job in JSON, then use setTimeout and jQuery.ajax() or Prototype's Ajax.PeriodicalUpdater to poll the server at regular intervals.

You don't need a big framework or Comet server to do this.


I ended up using a PeriodicalUpdater plugin for jQuery. Here's the link:

http://www.360innovate.co.uk/blog/2009/03/periodicalupdater-for-jquery/

0

精彩评论

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

关注公众号