Delayed job not executed despite disappearing from delayed_jobs table immediately

≯℡__Kan透↙ 提交于 2019-12-24 11:28:35

问题


I implemented a delayed job in my Rails application, following the instructions.

  1. I start the Rails app
  2. I click on a link that launches the delayed job
  3. The job is visible in the database's delayed_jobs table
  4. I run rake jobs:work
  5. The job disappears from the table, so I guess the job has been performed
  6. BUT PROBLEM: /tmp/job.log has not been written (what the job should have done)

The job:

class CsvImportJob
  def perform
    File.open('/tmp/job.log', 'w') {|f| f.write("Hello") }
  end
end

The call:

job = CsvImportJob.new
job.delay.perform

Nothing in the logs.
The rake jobs:work terminal says nothing after its start message:

[Worker(host:nico pid:25453)] Starting job worker

Nothing happen either when I launch the job while rake jobs:work is running.

In contrast, when the line "hello".delay.length is executed, delayed_jobs processes it and a message String#length completed after 0.0556 - 1 jobs processed at 3.6912 j/s, 0 failed does appear.


回答1:


See https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-undefined_method_xxx_for_class in documentation.

Even delayed_job author don't know the reason. It somehow depends on the webserver you run in on. Try the wiki's recommendation.

See also delayed_job: NoMethodError




回答2:


I'm a little late to the party, but also look at:

https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-jobs_are_silently_removed_from_the_database

Your case doesn't sound like a YAML deserialization error, but (as the WIKI suggests), you might set Delayed::Worker.destroy_failed_jobs = false so the failed job stays in the table and you can examine the cause of the error.

update

As I think about it: are you sure that the CsvImportJob class is known to the worker task? That is, is csv_import_job.rb defined in one of the "well known" directories for a Rails class? If not, then the worker task won't be able to de-serialize it, which will lead to exactly the behavior that you're seeing.

If for some reason, cav_import_job.rb is not in a well known directory, you can always require it from an initialization file -- that should fix the problem.



来源:https://stackoverflow.com/questions/7845874/delayed-job-not-executed-despite-disappearing-from-delayed-jobs-table-immediatel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!