Home Rails: How to send json response immediately for long running job
Reply: 1

Rails: How to send json response immediately for long running job

user2274074
1#
user2274074 Published in 2017-11-09 15:38:23Z

I am processing long running jobs. i am invoking long running method from controller. i want to send json response immediately to the user. below is my code but its not working.

def process
 p = Proces.new(:status => "in-progress")
 render :json => {:id => process.id}
 long_running_job()
end

How can i send json response immediately?

Daniel Westendorf
2#
Daniel Westendorf Reply to 2017-11-09 17:19:16Z

You need to run your long_running_job in a background job queue. This will make your long running task occur outside of the web request cycle, allowing you to return the JSON immediately, while your long running processes continues elsewhere. Look into ActiveJob if you're on Rails 4.2+ and/or Sidekiq.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.339532 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO