Class: Sidekiq::LimitFetch::Local::Semaphore

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/limit_fetch/local/semaphore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#busyObject (readonly)

Returns the value of attribute busy.



3
4
5
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 3

def busy
  @busy
end

#limitObject

Returns the value of attribute limit.



3
4
5
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 3

def limit
  @limit
end

Instance Method Details

#acquireObject



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

#blockObject



43
44
45
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 43

def block
  @block = true
end

#blocking?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 51

def blocking?
  @block
end

#pauseObject



31
32
33
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 31

def pause
  @paused = true
end

#paused?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 39

def paused?
  @paused
end

#releaseObject



25
26
27
28
29
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 25

def release
  @lock.synchronize do
    @busy -= 1
  end
end

#unblockObject



47
48
49
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 47

def unblock
  @block = false
end

#unpauseObject



35
36
37
# File 'lib/sidekiq/limit_fetch/local/semaphore.rb', line 35

def unpause
  @paused = false
end