Class: Gitlab::Database::LockRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/lock_recorder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



6
7
8
# File 'lib/gitlab/database/lock_recorder.rb', line 6

def self.instance
  Thread.current[:lock_recorder] ||= new
end

.record_key(record) ⇒ Object



10
11
12
# File 'lib/gitlab/database/lock_recorder.rb', line 10

def self.record_key(record)
  [record.class.table_name, record.id]
end

Instance Method Details

#add(record, lock_type) ⇒ Object



18
19
20
21
22
# File 'lib/gitlab/database/lock_recorder.rb', line 18

def add(record, lock_type)
  key = LockRecorder.record_key(record)

  locks[key] = lock_type
end

#clearObject



41
42
43
# File 'lib/gitlab/database/lock_recorder.rb', line 41

def clear
  locks.clear
end

#locksObject



14
15
16
# File 'lib/gitlab/database/lock_recorder.rb', line 14

def locks
  @locks ||= {}
end

#recordingObject



24
25
26
27
# File 'lib/gitlab/database/lock_recorder.rb', line 24

def recording
  @recording = false unless defined?(@recording)
  @recording
end

#recording?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/gitlab/database/lock_recorder.rb', line 37

def recording?
  recording
end

#startObject



29
30
31
# File 'lib/gitlab/database/lock_recorder.rb', line 29

def start
  @recording = true
end

#stopObject



33
34
35
# File 'lib/gitlab/database/lock_recorder.rb', line 33

def stop
  @recording = false
end