gem 'delayed_job_active_record'
bundle install
rails generate delayed_job:active_record
rake db:migrate
# without delayed_job
Notifier.signup(@user).deliver
# with delayed_job
Notifier.delay.signup(@user)
# with delayed_job running at a specific time
Notifier.delay(run_at: 5.minutes.from_now).signup(@user)
class LongTasks
def send_mailer
# Some other code
end
handle_asynchronously :send_mailer, :priority => 20
def in_the_future
# Some other code
end
# 5.minutes.from_now will be evaluated when in_the_future is called
handle_asynchronously :in_the_future, :run_at => Proc.new { 5.minutes.from_now }
def self.when_to_run
2.hours.from_now
end
def call_a_class_method
# Some other code
end
handle_asynchronously :call_a_class_method, :run_at => Proc.new { when_to_run }
attr_reader :how_important
def call_an_instance_method
# Some other code
end
handle_asynchronously :call_an_instance_method, :priority => Proc.new {|i| i.how_important }
end
RAILS_ENV=production bin/delayed_job start
RAILS_ENV=production bin/delayed_job stop
RAILS_ENV=production bin/delayed_job restart
rake jobs:clear
# for delayed job
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
after 'deploy:publishing', 'deploy:restart'