Rails async jobs (fast view and minimal delay)
Hi I have developed a rails app.
When one controller receives a request, it will render a client view AND send another action to a LED ticker display via TCP/IP. BUT send stuff to LED ticker display takes about 3 second. And I might have 5-10 LED ticker to send.
This will block client view rendering. (I can use multi-thread to send to each LED ticker display, but still have to delay 3-5 seconds when thread queue joins)
Question: Since client view has开发者_Go百科 nothing to do regardlessly if sending to LED fails.
- Can I make it an async job?HOW?
- Should I make a Sinatra background process listens stuff and send to LED by the sinatra app?
Thanks!
The spawn-plugin from https://github.com/tra/spawn should do nicely and can use forking (by default), threads or yields.
I use spawn with fork for long-running, fairly heavy tasks and it works like a charm. A simple example would be :
spawn(:method => :fork) do
do_led_stuff()
end
and since you don't require any feedback from the LED-ticker you won't have to wait() for the spawned process either.
Have you tried delayed_job (http://rubygems.org/gems/delayed_job)? I don't know if it's compatible with Sinatra, but maybe you can have a look at it.
You can use Resque (https://github.com/defunkt/resque)
精彩评论