#9 ActiveJob


ActiveJob is a built in wrapper within Rails 4 for your background processors. By adding this layer to your application, swapping background processors is much easier as you will only be affecting a limited number of files.
rails activejob background processing 5:24


bashrails generate job contact_mailer
app/jobs/contact_mailer_job.rb  class ContactMailerJob < ActiveJob::Base
    queue_as :default

    def perform(from,subject,message)
visitors_controller.rb  ContactMailerJob.perform_later(from,subject,message)
Gemfile  gem 'daemons'
  gem 'delayed_job'
  gem 'delayed_job_active_record'
  gem 'whenever', require: false
bash  rails generate delayed_job:active_record
  rake db:migrate
config/application.rb  config.active_job.queue_adapter = :delayed_job
config/schedule.rb  every :reboot do
    #`bin/delayed_job -n2 start`
    command 'bin/delayed_job -n2 start'
bash  whenever -help
  whenever -w
  crontab -l
Schwad said almost 2 years ago:

I've never had much opportunity to play with activejob, watching this made the entire process seem not that intimidating at all. Thanks so much for the screencast!

sandric mora said 12 months ago:

I think you got error, you do not actually delivering mail, you just render it inside perform method. I was watching video with that specific purpose, with question in my head - should you use deliver_now or deliver_later if you sending email with active job perform_later method.

kobaltz PRO said 12 months ago:

Personally, I would probably use deliver_now. The background job is already asynchronous so there isn't much point to loop back to another job. However, if I were sending many emails within a background job, I would use deliver_later.

Login to Comment