soon as the queuing system is # free. # Enqueue a job to be performed 1 week from now. DailyReportJob.perform_later(event1, event 2) DailyReportJob.set(wait: 1.week).perform_later(event)
# Be sure to have the adapter's gem in your Gemfile # and follow the adapter's specific installation # and deployment instructions. config.active_job.queue_adapter = :sidekiq end end
3 4 rescue_from(ActiveRecord::RecordNotFound) do |exception| 5 # Do something with the exception 6 end 7 8 def perform(*args) 9 # Do something later 10 end 11 end Catch Exceptions
send the email now use #deliver_now UserMailer.welcome(@user).deliver_now # If you want to send the email through Active Job use #deliver_later UserMailer.welcome(@user).deliver_later
3 class BillingJobTest < ActiveJob::TestCase 4 test 'that account is charged' do 5 BillingJob.perform_now(account, product) 6 assert account.reload.charged_for?(product) 7 end 8 end By default, ActiveJob::TestCase will set the queue adapter to :test so that your jobs are performed inline.
ProductTest < ActiveJob::TestCase 4 test 'billing job scheduling' do 5 assert_enqueued_with(job: BillingJob) do 6 product.charge(account) 7 end 8 end 9 end