[英]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. 我有一个after_create :get_geolocation
函数,在创建新用户后运行。
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. 由于如果正在使用的地理位置服务关闭,则它将中断注册。
Models can't seem to call request.remote_ip
. 模型似乎无法调用request.remote_ip
。 Could this function be somehow moved into a controller for request.remote_ip
to work? 可以将此功能以某种方式移入控制器以使request.remote_ip
正常工作吗?
You could use Sidekiq , delayed_job , resque , or another asynchronous task utility to perform the geolocation in the background. 你可以使用Sidekiq , delayed_job的 , resque或其他异步任务实用程序在后台执行的地理定位。 And for the IP, you could either store it in the model or send it along with your queue request. 对于IP,您既可以将其存储在模型中,也可以将其与队列请求一起发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.