Class: Sidekiq::LimitFetch::Global::Semaphore

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sidekiq/limit_fetch/global/semaphore.rb

Constant Summary collapse

PREFIX =
'limit_fetch'

Instance Method Summary collapse

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

#acquireObject



21
22
23
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 21

def acquire
  Selector.acquire([@name]).size > 0
end

#blockObject



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

Returns:

  • (Boolean)


53
54
55
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 53

def blocking?
  redis {|it| it.get "#{PREFIX}:block:#@name" }
end

#busyObject



29
30
31
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 29

def busy
  redis {|it| it.llen "#{PREFIX}:busy:#@name" }
end

#limitObject



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

#pauseObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 41

def paused?
  redis {|it| it.get "#{PREFIX}:pause:#@name" }
end

#releaseObject



25
26
27
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 25

def release
  Selector.release [@name]
end

#unblockObject



49
50
51
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 49

def unblock
  redis {|it| it.del "#{PREFIX}:block:#@name" }
end

#unpauseObject



37
38
39
# File 'lib/sidekiq/limit_fetch/global/semaphore.rb', line 37

def unpause
  redis {|it| it.del "#{PREFIX}:pause:#@name" }
end