Feature request: Support passing options for dependent: :purge_later for ActiveStorage attachment associations

Currently, when defining a has_one_attached association, you can specify dependent: :purge_later to asynchronously purge the Blob when the associated ActiveStorage::Attachment record is deleted from the database. This is the default behavior, and it works well for most cases.

However, there are cases where you may want to be able to pass additional options to the underlying ActiveJob that will be run, such as a time to wait, etc. It’s possible to get around this today using normal model callbacks, and that’s fine.

I’m wondering if there is any appetite for something like dependent: {purge_later: {wait: 8.hours}} or even just dependent: {purge_later: 8.hours}. I think the change wouldn’t be too bad to implement, and I would be happy to take it on if there’s an appetite for it.

I believe this is the relevant code in Rails core: rails/activestorage/app/models/active_storage/attachment.rb at 747f85f200e7bb2c1a31b4e26e5a5655e2dc0cdc · rails/rails · GitHub

1 Like