Rubies,
Wanna to implement background job with rails application? than use delayed job. https://github.com/collectiveidea/delayed_job
To install delayed job either via plugin or gem.
environment.rb file mention
config.gem ‘delayed_job’
on command prompt:
gem install delayed_job
rake generate delayed_job
rake db:migrate
Now in create custom job interface by adding custom ruby code.
class EmailJob < Struct.new(:args)
def perform
args[:emails].each { |e| AppMailer.deliver_text_to_email(args[:content], e) }
end
end
To invoke above job using below command.
Delayed::Job.enqueue EmailJob.new('Invitation to join ruby conference at india !!', User.all.collect(&:email))
Once you invoke the above statement it will create the delayed job but than we need to execute it by using delayed_job inbuilt rake task.
rake jobs:work
Oops! will you find error? No such rake found etc..? Hmm.. Do you know what are you missing?
Let me give you hint.
– Above error indicate delayed_job's tasks are not loaded with you rails. So for that we have modify application's Rakefile.
Refer http://priyanka-railsdeveloper.blogspot.in/2012/06/jobswork-fails.html
Hope, This article will be useful.