Class: Sidekiq::LimitFetch::Local::Semaphore
- Inherits:
-
Object
- Object
- Sidekiq::LimitFetch::Local::Semaphore
- Defined in:
- lib/sidekiq/limit_fetch/local/semaphore.rb
Instance Attribute Summary collapse
-
#busy ⇒ Object
readonly
Returns the value of attribute busy.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#unblocked ⇒ Object
readonly
Returns the value of attribute unblocked.
Instance Method Summary collapse
- #acquire ⇒ Object
- #block ⇒ Object
- #block_except(*queues) ⇒ Object
- #blocking? ⇒ Boolean
-
#initialize(name) ⇒ Semaphore
constructor
A new instance of Semaphore.
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #release ⇒ Object
- #unblock ⇒ Object
- #unpause ⇒ Object
Constructor Details
#initialize(name) ⇒ Semaphore
Returns a new instance of Semaphore.
5 6 7 8 9 10 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 5 def initialize(name) @name = name @lock = Mutex.new @busy = 0 @paused = false end |
Instance Attribute Details
#busy ⇒ Object (readonly)
Returns the value of attribute busy.
3 4 5 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 3 def busy @busy end |
#limit ⇒ Object
Returns the value of attribute limit.
3 4 5 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 3 def limit @limit end |
#unblocked ⇒ Object (readonly)
Returns the value of attribute unblocked.
3 4 5 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 3 def unblocked @unblocked end |
Instance Method Details
#acquire ⇒ Object
18 19 20 21 22 23 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 18 def acquire return if @paused @lock.synchronize do @busy += 1 if not @limit or @limit > @busy end end |
#block ⇒ Object
43 44 45 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 43 def block @block = true end |
#block_except(*queues) ⇒ Object
47 48 49 50 51 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 47 def block_except(*queues) raise ArgumentError if queues.empty? @unblocked = queues @block = true end |
#blocking? ⇒ Boolean
57 58 59 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 57 def blocking? @block end |
#pause ⇒ Object
31 32 33 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 31 def pause @paused = true end |
#paused? ⇒ Boolean
39 40 41 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 39 def paused? @paused end |
#release ⇒ Object
25 26 27 28 29 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 25 def release @lock.synchronize do @busy -= 1 end end |
#unblock ⇒ Object
53 54 55 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 53 def unblock @block = false end |
#unpause ⇒ Object
35 36 37 |
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 35 def unpause @paused = false end |