Class: Sidekiq::Processor::SharedWorkState

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

#initializeSharedWorkState

Returns a new instance of SharedWorkState.



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

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

Instance Method Details

#clearObject



258
259
260
# File 'lib/sidekiq/processor.rb', line 258

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

#delete(tid) ⇒ Object



246
247
248
# File 'lib/sidekiq/processor.rb', line 246

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

#dupObject



250
251
252
# File 'lib/sidekiq/processor.rb', line 250

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

#set(tid, hash) ⇒ Object



242
243
244
# File 'lib/sidekiq/processor.rb', line 242

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

#sizeObject



254
255
256
# File 'lib/sidekiq/processor.rb', line 254

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