Background jobs Flashcards
How to generate a new background job?
rails g job job_name
What does a job file include?
class NameJob < ApplicationJob queue_as :default
def perform(*args)
# Do something later
end
end
How to run the job? ( 2 ways )
NameJob.perform_now
NameJob.perform_later
What are the difference between sidekiq worker and rails job?
Short answer is they are the same thing. ActiveJob calls it a Job whereas Sidekiq calls it a Worker. I’ve decided to keep the terminology different so that people can distinguish the two.
You can use either one. Note that ActiveJob does not provide access to the full set of Sidekiq options so if you want to customize options for your job you might need to make it a Worker.
What queuing backend tools do you know?
- Sidekiq
- Rescue
- DelayedJob
How to clear all Sidekiq queries?
Sidekiq::Queue.all.each {|q| q.clear}