Challenge 1: A Basic Job — Solution # app/jobs/resize_image_job.rb class ResizeImageJob < ApplicationJob queue_as :default def perform(image_id) image = Image.find(image_id) image.resize! end end # app/controllers/images_controller.rb def create @image = Image.create!(image_params) ResizeImageJob.perform_later(@image.id) redirect_to @image end =begin Notes: - perform(image_id) takes the ID, not the Image object itself -- by the time a worker actually picks this job up, the object built in the controller is long gone; looking the record up fresh inside perform guarantees current data instead of a stale in-memory snapshot. - Image.find(image_id) raises ActiveRecord::RecordNotFound on its own if the image was deleted before the job ran, which is exactly the failure Challenge 2's discard_on is meant to handle. - perform_later enqueues and returns immediately -- the create action's redirect_to @image fires right away, without waiting for the resize to actually happen. =end