Class: Sidekiq::Processor::SharedWorkerState

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/processor.rb

Overview

jruby’s Hash implementation is not threadsafe, so we wrap it in a mutex here

Instance Method Summary collapse

Constructor Details

#initializeSharedWorkerState

Returns a new instance of SharedWorkerState.



223
224
225
226
# File 'lib/sidekiq/processor.rb', line 223

def initialize
  @worker_state = {}
  @lock = Mutex.new
end

Instance Method Details

#clearObject



244
245
246
# File 'lib/sidekiq/processor.rb', line 244

def clear
  @lock.synchronize { @worker_state.clear }
end

#delete(tid) ⇒ Object



232
233
234
# File 'lib/sidekiq/processor.rb', line 232

def delete(tid)
  @lock.synchronize { @worker_state.delete(tid) }
end

#dupObject



236
237
238
# File 'lib/sidekiq/processor.rb', line 236

def dup
  @lock.synchronize { @worker_state.dup }
end

#set(tid, hash) ⇒ Object



228
229
230
# File 'lib/sidekiq/processor.rb', line 228

def set(tid, hash)
  @lock.synchronize { @worker_state[tid] = hash }
end

#sizeObject



240
241
242
# File 'lib/sidekiq/processor.rb', line 240

def size
  @lock.synchronize { @worker_state.size }
end