Ruby on rails 在上使用DelayedJob运行\u限制地理编码请求

Ruby on rails 在上使用DelayedJob运行\u限制地理编码请求,ruby-on-rails,ruby,delayed-job,rails-geocoder,Ruby On Rails,Ruby,Delayed Job,Rails Geocoder,我正在尝试在Rails应用程序中处理地理编码,以限制使用DelayedJob的地理编码api调用流 我的目的只是对地理编码请求进行排队,因为它们对用户的时间不敏感。此外,我正在使用免费的地理编码API(NAMMIT),它每秒只需要一个请求 我有geocoder gem设置,在我的用户模型中,我从用户帐户设置中获得邮政编码(它不能为空,我已经在验证它) 我的想法是开始使用run_at限制调用,但run_at的初始测试显示作业正在排队,但地理代码在完成时不保存值 after_validation :

我正在尝试在Rails应用程序中处理地理编码,以限制使用DelayedJob的地理编码api调用流

我的目的只是对地理编码请求进行排队,因为它们对用户的时间不敏感。此外,我正在使用免费的地理编码API(NAMMIT),它每秒只需要一个请求

我有geocoder gem设置,在我的用户模型中,我从用户帐户设置中获得邮政编码(它不能为空,我已经在验证它)

我的想法是开始使用run_at限制调用,但run_at的初始测试显示作业正在排队,但地理代码在完成时不保存值

after_validation :run_geocode, :if => :postcode_changed?

def run_geocode
   self.delay(:run_at => 30.seconds.from_now).geocode
end

我错过了一些很明显的东西吗?我无法确定文档所说的:geocode方法的用途。

如果不调用save anywhere,则可能无法保存geocoded响应。另外,通常在保存/更新/删除记录后而不是在验证后运行回调

after_save :run_geocode, :if => :postcode_changed?

def run_geocode
  self.delay.geocode! # delayed_job will process geocode! at a later point in time
end

def geocode!
  # do whatever is nescessary to receive geocoded infos
  # assign the results
  # save the record to save the updates
  self.save
end

如果不调用save anywhere,则可能不会保存地理编码的响应。另外,通常在保存/更新/删除记录后而不是在验证后运行回调

after_save :run_geocode, :if => :postcode_changed?

def run_geocode
  self.delay.geocode! # delayed_job will process geocode! at a later point in time
end

def geocode!
  # do whatever is nescessary to receive geocoded infos
  # assign the results
  # save the record to save the updates
  self.save
end

谢谢Thomas,那么保存是否要等到地理编码响应到来?这会导致内存问题吗?或者我应该创建一个包含地理编码和保存的延迟方法吗?谢谢Thomas,保存要等到地理编码响应到来吗?这会导致内存问题吗?或者我应该创建一个包含地理代码和save的延迟方法吗?