Reputation: 5721
I am creating a delayed job in my controller using the delay method as below:
JobProcessor.delay(:run_at => Time.now).process_job(options)
Now inside the process_job method I am doing
chunks = options[:collection].each_splice(10).to_a
chunks.each do |chunk|
self.delay(:run_at => Time.now).chunk_job
end
This is giving me error stack level too deep
when I send request to the URL
What might be the issue? Please help.
Upvotes: 0
Views: 995
Reputation: 5721
I was able to make it work for me by doing some changes.
process_job
to be an instance methodSo now my code looks like
JobProcessor.new.process_job(options)
in the controller, and inside the JobProcessor
class I have
class JobProcessor
def process_job(options)
chunks = options[:collection].each_splice(10).to_a
chunks.each do |chunk|
self.class.delay(:run_at => Time.now).chunk_job(options)
end
end
handle_asynchronously :process_job, :run_at => Proc.new { 2.seconds.from_now }
def self.chunk_job(options)
# perform chunk job here
end
end
This works for me.
Upvotes: 1