Jobs queue are not adding in delayed_jobs table, when it is daemonized. But that works when it is not daemonized.
当任务队列被精灵化时,它不会添加到delayed_jobs表中。但当它没有被妖魔化时,它就会起作用。
I have three rake tasks(a.rake, b.rake, c.rake).
我有三个耙任务。耙,b。耙,c.rake)。
In a.rake
在a.rake
task :run_a => :environment do
A.new.get_a_data
end
class A
def get_a_data
...
schedule_next_a_job
end
def schedule_next_a_job
get_a_data
end
handle_asynchronously :get_a_data, :run_at => Proc.new { 2.minutes.from_now }, :queue => 'a'
end
In b.rake
在b.rake
task :run_b => :environment do
B.new.get_b_data
end
class B
def get_b_data
...
schedule_next_b_job
end
def schedule_next_b_job
get_b_data
end
handle_asynchronously :get_b_data, :run_at => Proc.new { 5.minutes.from_now }, :queue => 'b'
end
In c.rake
在c.rake
namespace :run do
task :start do
`rake run_a`
`rake run_b`
if Rails.env == 'development'
`QUEUES=a,b rake jobs:work`
else
`RAILS_ENV=production bin/delayed_job --queues=a,b start`
end
task :stop do
`rake jobs:clear`
end
end
In console, i run like below:
在控制台,我运行如下:
RAILS_ENV=production rake run:start # to start jobs worker
rake run:stop # to clear my jobs worker
In my delayed jobs table last_error is showing as:
在我的延迟作业表last_error中显示为:
Job failed to load: undefined class/module A
工作失败:未定义的类/模块A。
Job failed to load: undefined class/module B
作业装载失败:未定义的类/模块B
Can anyone help me to get rid of this problem?
有人能帮我解决这个问题吗?
Thanks in Advance.
提前谢谢。
1 个解决方案
#1
2
One common cause of deserialization errors is that the YAML references a class not known to the worker. If this is the case, you can add
反序列化错误的一个常见原因是YAML引用了一个不知道该worker的类。如果是这样,你可以加上
# file: config/initializers/custom.rb
require 'my_custom_class'
which will force my_custom_class
to be loaded when the worker starts. Reference
这将强制在worker启动时加载my_custom_class。参考
#1
2
One common cause of deserialization errors is that the YAML references a class not known to the worker. If this is the case, you can add
反序列化错误的一个常见原因是YAML引用了一个不知道该worker的类。如果是这样,你可以加上
# file: config/initializers/custom.rb
require 'my_custom_class'
which will force my_custom_class
to be loaded when the worker starts. Reference
这将强制在worker启动时加载my_custom_class。参考