class Asset < ApplicationRecord
after_save_commit :enqueue_processing, if: :saved_change_to_file_key?
private
def enqueue_processing
Assets::ProcessJob.perform_later(id)
end
end
Heavy work inside a transaction increases lock time and deadlock risk. Use after_save_commit to schedule slow tasks (thumb generation, external sync) once the write is durable.