Running with patch
$ QUEUE_ADAPTER=async ./fix-preview-image-race-condition.rb
Yields
Creating a post and uploading a video
Setting queue adapter to async
================================================================================
Record counts before doing anything (created after 2024-01-31 18:21:12 UTC):
- 0 Posts []
- 0 Visuals []
- 0 ActiveStorage::Blobs []
- 0 ActiveStorage::Attachments []
- 0 ActiveStorage::VariantRecords []
================================================================================
Record counts after attaching '/Users/justin/code/searls/grog/test/fixtures/files/video.mp4' (created after 2024-01-31 18:21:12 UTC):
- 1 Post [39]
- 1 Visual [44]
- 1 ActiveStorage::Blob [168]
- 1 ActiveStorage::Attachment [152]
- 0 ActiveStorage::VariantRecords []
================================================================================
Record counts after letting preprocess jobs run (created after 2024-01-31 18:21:12 UTC):
- 1 Post [39]
- 1 Visual [44]
- 5 ActiveStorage::Blobs [168, 169, 170, 171, 172]
- 5 ActiveStorage::Attachments [152, 153, 154, 155, 156]
- 2 ActiveStorage::VariantRecords [79, 80]
================================================================================
Record counts after destroying post (created after 2024-01-31 18:21:12 UTC):
- 0 Posts []
- 0 Visuals []
- 5 ActiveStorage::Blobs [168, 169, 170, 171, 172]
- 4 ActiveStorage::Attachments [153, 154, 155, 156]
- 2 ActiveStorage::VariantRecords [79, 80]
================================================================================
Record counts after letting purge jobs run (created after 2024-01-31 18:21:12 UTC):
- 0 Posts []
- 0 Visuals []
- 2 ActiveStorage::Blobs [170, 172]
- 2 ActiveStorage::Attachments [154, 156]
- 1 ActiveStorage::VariantRecord [80]
As the above shows, 5 database records remain after purge (and 2 blobs are left in storage).