thread safety - Is this async Rails action safe? -
I am trying to do asynchronous and non-blocking a rail action. I am using Rail 3.2 and thin web server. Is the following code safe?
Class AnalyticsController & lt; ApplicationController # [...] # When displaying a XHR request, def loads a spinner in the main page while loading the load. Nue do @answer = Analytic.build_stuff_with_blocking_io # can take up to 60sec request.env ['async.callback'] .col [200, {}, render_to_string (partial: '/ analytics / dashboard', layout: incorrect)] End throw: async end end Here's an example of how to perform async rail:
class ApplicationController & lt; ActionController :: Base Def async EM.defer do sleep 5 # Some tasks that take long call.env ['async.callback']. Throw the call response end: async end end
Be sure that you have config.allow_concurrency = true
in your environment
if you tap Using:
Bundle Excel Thin - Started Start
/ P>
Comments
Post a Comment