Class: Batch

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

Class Method Summary collapse

Methods included from Sufia::Lockable

acquire_lock_for, lock_manager

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

This method handles most race conditions gracefully.



14
15
16
17
18
19
20
21
22
# File 'app/models/batch.rb', line 14

def self.find_or_create(id)
  acquire_lock_for(id) do
    begin
      Batch.find(id)
    rescue ActiveFedora::ObjectNotFoundError
      Batch.create(id: id)
    end
  end
end