Class: Batch
- Inherits:
-
ActiveFedora::Base
- Object
- ActiveFedora::Base
- Batch
- Includes:
- Hydra::AccessControls::Permissions, Sufia::ModelMethods, Sufia::Noid
- Defined in:
- app/models/batch.rb
Class Method Summary collapse
- .find_or_create(id) ⇒ Object
-
.safe_create(id) ⇒ Object
This method handles most race conditions gracefully.
Methods included from Sufia::Noid
Methods included from Sufia::ModelMethods
Methods inherited from ActiveFedora::Base
#create_event, #events, #log_event, stream, #stream
Class Method Details
.find_or_create(id) ⇒ Object
12 13 14 15 16 |
# File 'app/models/batch.rb', line 12 def self.find_or_create(id) Batch.find(id) rescue ActiveFedora::ObjectNotFoundError safe_create(id) end |
.safe_create(id) ⇒ Object
This method handles most race conditions gracefully. If a batch with the same ID is created by another thread we fetch the batch that was created (rather than throwing an error) and continute.
22 23 24 25 26 27 28 29 |
# File 'app/models/batch.rb', line 22 def self.safe_create(id) Batch.create(id: id) rescue ActiveFedora::IllegalOperation # This is the exception thrown by LDP when we attempt to # create a duplicate object. If we can find the object # then we are good to go. Batch.find(id) end |