Class: Batch

Inherits:
ActiveFedora::Base show all
Includes:
Hydra::AccessControls::Permissions, Sufia::ModelMethods, Sufia::Noid
Defined in:
app/models/batch.rb

Class Method Summary collapse

Methods included from Sufia::Noid

#assign_id, #to_param

Methods included from Sufia::ModelMethods

#to_s

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