简体   繁体   English

Rails / delayed_job只是……不起作用

[英]Rails/delayed_job just… not working

I've spent about 3 hours trying to get a simple delayed_job to execute without success. 我花了大约3个小时来尝试执行一个简单的delayed_job ,但未成功执行。 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: 我将它加入一个Rails动作中,如下所示:

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, 以及诸如此类的delayed_backend_mongoid_jobs条目,

{ "_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. /tmp/mrsmee ,测试输出文件/tmp/mrsmee从未写入任何内容。 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? 为什么delayed_job实际上没有运行延迟的工作,或者至少告诉我是什么阻止了延迟的工作呢?

Probably a little bit in late but: 可能有点晚了,但是:

The problem is not with DelayedJob but with you method. 问题不在于DelayedJob,而在于您的方法。 DelayedJob is executing Foo.new.foo. DelayedJob正在执行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 并且您在DelayedJob的输出日志中看到该字符串,则delayJob正常工作

Have you checked that rails (DelayedJob) has permissions to write in /tmp folder? 您是否检查过Rails(DelayedJob)有权在/ tmp文件夹中写入?

this code might help as well (test.txt is created and written in your app folder): 此代码也可能有帮助(已创建test.txt并将其写入您的应用文件夹中):

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 如果这可行,即创建了test.txt文件且其内容为foo,则问题应该出在具有权限的地方,因此sudo script/delayed_job run可能会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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