我是延迟工作的新手,但在本地,宝石工作完美。在生产中,gem 在delayed_jobs 表中记录一个条目,然后在几毫秒内完成它,将其删除而不进行处理。
我发现的一个关键区别是在数据库中创建的处理程序条目。
当地的
--- !ruby/object:Delayed::PerformableMethod
object: !ruby/ActiveRecord:User
attributes:
id: '1'
email: abc@example.com.au
is_pending: pending
method_name: :job_without_delay
args:
- false
Heroku
--- !ruby/object:Delayed::PerformableMethod
attributes:
id: 1
email: abc@example.com.au
is_pending: pending
到底是怎么回事?有人可以帮忙吗?
控制器
def make_pending
@user = current_user
@user.job(false)
redirect_to user_path(current_user)
end
用户模型
def job(silence)
Project.job(self.id, silence)
end
handle_asynchronously :job, :run_at => Proc.new { 5.minutes.from_now }
另一个区别
本地日志
[Worker(host:__.local pid:5179)] Starting job worker
[Worker(host:__.local pid:5179)] User#job_without_delay completed after 417.0975
[Worker(host:__.local pid:5179)] 1 jobs processed at 0.0024 j/s, 0 failed ...
Heroku 日志
013-01-14T12:15:37+00:00 app[worker.1]: [Worker(host:19edbbfb-b8b9-4528-bca6-46ecac4e66bc pid:2)] NilClass# completed after 0.0119
2013-01-14T12:15:37+00:00 app[worker.1]: [Worker(host:19edbbfb-b8b9-4528-bca6-46ecac4e66bc pid:2)] 1 jobs processed at 26.9897 j/s, 0 failed ...