Files
fizzy/config/initializers/active_job.rb
T
Mike Dalessio 2c2a1c4b4a Make sure jobs are enqueued only after all transactions are committed
This should fix the recurring ActiveStorage::FileNotFoundError errors
from ActiveStorage::AnalyzeJob.

The issue is that, when images are not direct uploaded (e.g. a card
background image or avatar image), the AnalyzeJob has been getting
enqueued before the file itself was uploaded to blob storage.

Setting ActiveJob::Base.enqueue_after_transaction_commit = true makes
sure that jobs are always enqueued only once *all* transactions have
been committed.

This will be the Rails default at some point, but for now we still
need to explicitly set it.

Big thanks to @jeremy for the assist. 👏
2025-11-20 18:47:42 -05:00

40 lines
742 B
Ruby

# frozen_string_literal: true
# inspired from code in ActiveRecord::Tenanted
module FizzyActiveJobExtensions
extend ActiveSupport::Concern
prepended do
attr_reader :account
self.enqueue_after_transaction_commit = true
end
def initialize(...)
super
@account = Current.account
end
def serialize
super.merge({ "account" => @account&.to_gid })
end
def deserialize(job_data)
super
if _account = job_data.fetch("account", nil)
@account = GlobalID::Locator.locate(_account)
end
end
def perform_now
if account.present?
Current.with_account(account) { super }
else
super
end
end
end
ActiveSupport.on_load(:active_job) do
prepend FizzyActiveJobExtensions
end