0

可以说我做类似的事情

arrs = Article.where(:body => nil)

我会有 arrs.count 假设是 900 我会

arrs.each do |ar|
  ar.delay.download_via_diffbot #a method that takes some time, does some http, and writes a non-nil value to ar.body
end

现在我会看日志,然后在 ~5 dynos 上等待几分钟来完成工作,然后再次计数:arrs.count 现在是 ~800

所以wtf,我以为我只是告诉我的工人做〜900个工作,其他800个怎么了?

我可以确认我只发出了约 100 个 HTTP 请求 b/c api 报告向我展示了这一点,也只需查看日志就足以说明 900 个工作没有发生。


我正在关注 Delayed::Job.count 并且从该循环中只创建了大约 100 个,即使有数百个工作开始

我是否错误地创建了这么多同时工作?一次创造这么多工作的正确方法是什么?

4

1 回答 1

1

Mongoid criteria are lazy loaded/evaluated. That is to say if you set articles = Article.where(body: nil), articles is a criteria. It is not the set of documents you get from db. So if you delete some articles with body nil or fill in body of some articles, articles.count will fire another db query and only report number of articles for which body is nil. Reducing count is to be expected if your delayed workers are successfully doing their job and filling up body content.

PS: Question was not very clear, I just answered to what I comprehended the problem is.

UPDATE

You can check the delayed job count to see how many jobs are pending at any time by Delayed::Job.count. If you are not deleting the failed jobs, you can check the count of failed jobs by Delayed::Job.where(:failed_at.ne => nil).count. To see more details about failed jobs, you can inspect the job, it will have the handler and last error.

于 2012-10-20T22:54:10.020 回答