Skip AnalyzeJob when blob has no attachments
Upload-then-delete races cause AnalyzeJob to hit S3 after PurgeJob has already removed the object, producing Aws::S3::Errors::NoSuchKey noise in solid_queue_failed_executions. Since PurgeOnLastAttachment destroys the attachment row before enqueueing PurgeJob, checking blob.attachments.exists? catches this — a fast DB query that avoids the S3 round-trip entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
require "test_helper"
|
||||
|
||||
class ActiveStorageAnalyzeJobSuppressBroadcastsTest < ActiveSupport::TestCase
|
||||
test "skips analysis when blob has no attachments" do
|
||||
blob = ActiveStorage::Blob.create_and_upload!(
|
||||
io: StringIO.new("x" * 1024), filename: "orphan.txt", content_type: "text/plain"
|
||||
)
|
||||
|
||||
blob.expects(:analyze).never
|
||||
|
||||
ActiveStorage::AnalyzeJob.perform_now(blob)
|
||||
end
|
||||
|
||||
test "performs analysis when blob has attachments" do
|
||||
card = cards(:logo)
|
||||
card.image.attach io: StringIO.new("x" * 1024), filename: "test.png", content_type: "image/png"
|
||||
blob = card.image.blob
|
||||
|
||||
blob.expects(:analyze).once
|
||||
|
||||
ActiveStorage::AnalyzeJob.perform_now(blob)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user