ActiveJob

#9 ActiveJob
7/30/2015

Summary

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.
5
rails activejob background processing

Summary

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

    def perform(from,subject,message)
      ContactMailer.send_contact(from,subject,message)
    end
  end
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'
  end
bash  whenever -help
  whenever -w
  crontab -l
7865030?v=3&s=64
Schwad said 3 months 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!

Login to Comment