简体   繁体   中英

Rails: how to run a model callback function in the background?

I have a after_create :get_geolocation function that runs after a new user is created.

  1. Is there a way I can run this function in the background so that there is no delay for the user? Since if the geolocation service being used is down, it will break signups.

  2. Models can't seem to call request.remote_ip . Could this function be somehow moved into a controller for request.remote_ip to work?

You could use Sidekiq , delayed_job , resque , or another asynchronous task utility to perform the geolocation in the background. And for the IP, you could either store it in the model or send it along with your queue request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM