mirror of
https://github.com/deanpcmad/sidekiq-limit_fetch.git
synced 2022-11-09 13:54:36 -05:00
Add #pause and #release to Queue
This commit is contained in:
parent
3178329bcc
commit
e675cd367e
2 changed files with 16 additions and 1 deletions
|
@ -1,7 +1,12 @@
|
|||
module Sidekiq
|
||||
class Queue
|
||||
extend LimitFetch::Singleton, Forwardable
|
||||
def_delegators :lock, :limit, :limit=, :acquire, :release, :busy
|
||||
|
||||
def_delegators :lock,
|
||||
:limit, :limit=,
|
||||
:acquire, :release,
|
||||
:pause, :continue,
|
||||
:busy
|
||||
|
||||
def full_name
|
||||
@rname
|
||||
|
|
|
@ -4,6 +4,7 @@ class Sidekiq::LimitFetch::Semaphore
|
|||
def initialize
|
||||
@lock = Mutex.new
|
||||
@busy = 0
|
||||
@paused = false
|
||||
end
|
||||
|
||||
def limit=(value)
|
||||
|
@ -13,6 +14,7 @@ class Sidekiq::LimitFetch::Semaphore
|
|||
end
|
||||
|
||||
def acquire
|
||||
return if @paused
|
||||
@lock.synchronize do
|
||||
@busy += 1 if not @limit or @limit > @busy
|
||||
end
|
||||
|
@ -23,4 +25,12 @@ class Sidekiq::LimitFetch::Semaphore
|
|||
@busy -= 1
|
||||
end
|
||||
end
|
||||
|
||||
def pause
|
||||
@paused = true
|
||||
end
|
||||
|
||||
def continue
|
||||
@paused = false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue