以下を含むモデルがあります。
def fetch_austlii
Resque.enqueue(FetchAustliiJob, self.id) # Queue the job for later.
end
これにより、 app/workers/fetch_austlii_job.rb ファイルがディスパッチされます。
class FetchAustliiJob
@queue = :fetch_queue
def self.perform(profile_id)
@profile = Profile.find(profile_id)
AustliiResource.fetch(@profile.name).each do |resource|
@profile.austlii_resources.create!(resource.attributes) if @profile.austlii_resources.find_all_by_url(resource.url).empty?
end
end
end
開発中 (OS X、Ruby 1.9.2、Rails3、Postgres、Redis-server、Foreman) では問題なく動作します。このジョブは、必要に応じてインターネットから情報を取得します。ただし、本番環境 (Ubuntu、Ruby 1.9.2、Passenger) では次のように失敗します。
Class
FetchAustliiJob
Arguments
2
Exception
NoMethodError
Error
undefined method `austlii_resources' for #<Profile:0x00000002fab6b0>