Jobs queue are not adding in delayed_jobs table, when it is daemonized. But that works when it is not daemonized.
I have three rake tasks(a.rake, b.rake, c.rake).
In 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
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
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:
Job failed to load: undefined class/module A
Job failed to load: undefined class/module B
Can anyone help me to get rid of this problem?
Thanks in Advance.
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
# file: config/initializers/custom.rb
require 'my_custom_class'
which will force my_custom_class
to be loaded when the worker starts. Reference