Performance: Job creation and queuing
This affects page load speed and user interaction responsiveness by offloading heavy tasks to background jobs.
def create
UserMailer.welcome_email(@user).deliver_later
render :show
enddef create
UserMailer.welcome_email(@user).deliver_now
render :show
end| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous job execution | Minimal | Multiple reflows due to blocking | High paint cost due to delayed rendering | [X] Bad |
| Asynchronous job queuing | Minimal | Single reflow | Low paint cost, fast rendering | [OK] Good |
ApplicationJob?SendEmailJob to run later?perform_later adds the job to the queue for later execution.perform_now runs immediately, enqueue and run_later are not valid Rails job methods.class CleanupJob < ApplicationJob
def perform
puts 'Cleaning up!'
end
end
CleanupJob.perform_later?perform_later queues the job to run asynchronously later, not immediately.class NotifyUserJob < ApplicationJob
def perform(user_id)
User.find(user_id).notify
end
end
NotifyUserJob.perform_laterperform_later without arguments causes an error because user_id is missing.perform?user.verified? inside perform and send email only if true correctly checks verification inside perform before sending email, ensuring only verified users get emails.Pass the test and this pattern moves unknown