Class: Sidekiq::LimitFetch::Global::Semaphore
- Inherits:
-
Object
- Object
- Sidekiq::LimitFetch::Global::Semaphore
- Extended by:
- Forwardable
- Defined in:
- lib/sidekiq/limit_fetch/global/semaphore.rb
Constant Summary collapse
- PREFIX =
'limit_fetch'
Instance Method Summary collapse
- #acquire ⇒ Object
- #block ⇒ Object
- #blocking? ⇒ Boolean
- #busy ⇒ Object
-
#initialize(name) ⇒ Semaphore
constructor
A new instance of Semaphore.
- #limit ⇒ Object
- #limit=(value) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #release ⇒ Object
- #unblock ⇒ Object
- #unpause ⇒ Object
Constructor Details
#initialize(name) ⇒ Semaphore
Returns a new instance of Semaphore.
8 9 10 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 8 def initialize(name) @name = name end |
Instance Method Details
#acquire ⇒ Object
21 22 23 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 21 def acquire Selector.acquire([@name]).size > 0 end |
#block ⇒ Object
45 46 47 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 45 def block redis {|it| it.set "#{PREFIX}:block:#@name", true } end |
#blocking? ⇒ Boolean
53 54 55 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 53 def blocking? redis {|it| it.get "#{PREFIX}:block:#@name" } end |
#busy ⇒ Object
29 30 31 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 29 def busy redis {|it| it.llen "#{PREFIX}:busy:#@name" } end |
#limit ⇒ Object
12 13 14 15 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 12 def limit value = redis {|it| it.get "#{PREFIX}:limit:#@name" } value.to_i if value end |
#limit=(value) ⇒ Object
17 18 19 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 17 def limit=(value) redis {|it| it.set "#{PREFIX}:limit:#@name", value } end |
#pause ⇒ Object
33 34 35 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 33 def pause redis {|it| it.set "#{PREFIX}:pause:#@name", true } end |
#paused? ⇒ Boolean
41 42 43 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 41 def paused? redis {|it| it.get "#{PREFIX}:pause:#@name" } end |
#release ⇒ Object
25 26 27 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 25 def release Selector.release [@name] end |
#unblock ⇒ Object
49 50 51 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 49 def unblock redis {|it| it.del "#{PREFIX}:block:#@name" } end |
#unpause ⇒ Object
37 38 39 |
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 37 def unpause redis {|it| it.del "#{PREFIX}:pause:#@name" } end |