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.



208
209
210
211
# File 'lib/sidekiq/processor.rb', line 208

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

Instance Method Details

#clearObject



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

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

#delete(tid) ⇒ Object



217
218
219
# File 'lib/sidekiq/processor.rb', line 217

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

#dupObject



221
222
223
# File 'lib/sidekiq/processor.rb', line 221

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

#set(tid, hash) ⇒ Object



213
214
215
# File 'lib/sidekiq/processor.rb', line 213

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

#sizeObject



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

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