简体   繁体   中英

Rails/delayed_job just… not working

I've spent about 3 hours trying to get a simple delayed_job to execute without success. I have this extremely simple job:

class Foo
  def foo
    `echo foo >> /tmp/mrsmee`
  end
end

I'm enqueueing it in a Rails action like so:

Foo.new.delay.foo()

I'm running the job processor like so:

$ script/delayed_job run

I see a bunch of output logs like this,

2013-05-13T15:21:12-0700: [Worker(delayed_job host:asha.local pid:73263)] 1 jobs processed at 35.6405 j/s, 0 failed ...

and entries in the delayed_backend_mongoid_jobs like this,

{ "_id" : ObjectId("51916452005056107900001a"), "priority" : 0, "attempts" : 0, "queue" : null, "handler" : "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/object:Foo {}\nmethod_name: :foo\nargs: []\n", "run_at" : ISODate("2013-05-13T22:08:18.560Z"), "updated_at" : ISODate("2013-05-13T22:08:18.560Z"), "created_at" : ISODate("2013-05-13T22:08:18.560Z") }

so clearly the jobs are being enqueued, processed, and dequeued. Too bad the test output file, /tmp/mrsmee , never gets anything written to it. I'm at a total loss. Why isn't delayed_job actually running the delayed jobs, or at least telling me what's keeping it from doing so?

Probably a little bit in late but:

The problem is not with DelayedJob but with you method. DelayedJob is executing Foo.new.foo.

If you try this:

class Foo
  def foo
    puts "hey!, the job is being executed!"
  end
end

and you see that string in the DelayedJob's output log, then delayedJob is working properly

Have you checked that rails (DelayedJob) has permissions to write in /tmp folder?

this code might help as well (test.txt is created and written in your app folder):

class Foo
  def foo
    `echo foo >> #{Rails.root.join "test.txt"}` #remember to delete test.txt!
  end
end

If this works, ie test.txt file is created and its content is foo, the problem should be something with permissions so sudo script/delayed_job run might help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM