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.



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

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

Instance Method Details

#clearObject



268
269
270
# File 'lib/sidekiq/processor.rb', line 268

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

#delete(tid) ⇒ Object



256
257
258
# File 'lib/sidekiq/processor.rb', line 256

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

#dupObject



260
261
262
# File 'lib/sidekiq/processor.rb', line 260

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

#set(tid, hash) ⇒ Object



252
253
254
# File 'lib/sidekiq/processor.rb', line 252

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

#sizeObject



264
265
266
# File 'lib/sidekiq/processor.rb', line 264

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