- Use ActiveJob
- Use different adapters: Sidekiq, Resque
- Backend adapters depend on workers to execute jobs
- Use queues for different kind of jobs / tasks: mailing, maintenance, etc.
- Job perform callbacks are available as well
- ActionMailer can work as an ActiveJob
- Watch out for Thread safety - pay attention to instance variables and how they are accessed and changed in concurrent processes. One option is to use Mutex
- Sidekiq > Resque > DelayedJob (But it depends on the needs and available resources)
ActiveJob Basics Testing ActiveJob
rails generate job job_name --queue job_queueTestJob.perform_later(args)
TestJob.set(wait_until: Date.tomorrow.noon).perform_later(args)
TestJob.set(wait: 1.week).perform_later(args)
TestJob.perform_later(arg1, arg2, filter: 'some_filter')ActionMailer can work as ActiveJob. To send mails as a job (user won't have to wait):
UserMailer.welcome(@user).deliver_now
vs
UserMailer.welcome(@user).deliver_later