Class: M365ActiveStorage::PendingDelete
- Inherits:
-
Object
- Object
- M365ActiveStorage::PendingDelete
- Defined in:
- lib/m365_active_storage/pending_delete.rb
Overview
Pending Deletion Storage
Manages filename mapping during blob deletion to support deferred deletion from SharePoint.
Purpose
When an ActiveStorage blob is destroyed, the blob record is deleted from the database immediately. However, the actual file deletion from SharePoint may need to happen asynchronously. This class provides thread-safe storage to maintain the mapping between blob keys and filenames after the blob is deleted so that background workers can retrieve the filename and delete the file from SharePoint.
Thread Safety
All operations are protected by a Mutex to ensure thread-safe access in concurrent environments (e.g., multiple Sidekiq workers).
Architecture
PendingDelete acts as a temporary in-memory registry. When a blob is destroyed:
-
The before_destroy callback stores the key -> filename mapping
-
A background job retrieves the filename and deletes from SharePoint
-
The mapping is removed from storage
Note: This is an in-memory store and will be lost if the process restarts. For production use, consider backing this with Redis or a database table.
Class Method Summary collapse
-
.get(key) ⇒ String?
Retrieve and remove a filename from the pending deletion registry.
-
.store(key, filename) ⇒ void
Store a blob key and filename for later retrieval during deletion.
Class Method Details
.get(key) ⇒ String?
Retrieve and remove a filename from the pending deletion registry
Thread-safe method to get a filename by key and remove it from storage. Called by background deletion workers to get the filename for SharePoint deletion.
71 72 73 74 75 |
# File 'lib/m365_active_storage/pending_delete.rb', line 71 def self.get(key) @mutex.synchronize do @pending_deletes.delete(key) end end |
.store(key, filename) ⇒ void
This method returns an undefined value.
Store a blob key and filename for later retrieval during deletion
Thread-safe method to add a key-filename pair to the pending deletion registry. Called by the Railtie before_destroy callback when a blob is deleted.
52 53 54 55 56 |
# File 'lib/m365_active_storage/pending_delete.rb', line 52 def self.store(key, filename) @mutex.synchronize do @pending_deletes[key] = filename end end |