4
Carrierwave only deletes the 'mounted' file after the object in the database has been removed:
after_commit :remove_avatar! :on => :destroy
https://github.com/carrierwaveuploader/carrierwave
I am implementing a Backgrounddestroyable Center and for that I have a worker who deletes the files.
The field deleted_at
records when the object was marked for complete removal and to ensure that the objects are only actually removed by the worker I needed to reset the destroy
at the conference.
If one of the Workers receives a timeout I lose the reference of my orphaned files in S3, since my objects in the database have been deleted.
What should I do to make sure I don’t end up with orphans in S3?
Call remove_avatar!
right before the object.destroy
and then make a skip_callback?
It’s safe to do that?
Sorry, I don’t understand the part of Timeout, what gets Timeout? Your script or Amazon?
– Ricardo
@Ricardo my script (in case my worker Rails) is the one who receives the timeout. For some reason he may not be able to communicate with S3 while proceeding with file deletions and hence orphans problem.
– Rafael Oliveira
before_destroy :remove_avatar!
??– Rodrigo
My problem is that I was doing a Concern for soft delete (Backgrounddestroyable) and the logic got a little more complex (I was resetting Destroy and removing the file in before_destroy would not work). Anyway I think it’s okay to call the
before_destroy :remove_avatar!
even if the carrierwave will call the method again after the commit.– Rafael Oliveira