Class: Workers::BucketScheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/workers/bucket_scheduler.rb

Constant Summary collapse

DEFAULT_BUCKET_SIZE =
100
DEFAULT_POOL_SIZE =
1

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BucketScheduler

Returns a new instance of BucketScheduler.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/workers/bucket_scheduler.rb', line 6

def initialize(options = {})
  options[:bucket_size] ||= DEFAULT_BUCKET_SIZE
  options[:pool_size] ||=  DEFAULT_POOL_SIZE

  @logger = Workers::LogProxy.new(options[:logger])
  @options = options

  @schedulers = (0...(options[:bucket_size])).map {
    Workers::Scheduler.new(:pool => Workers::Pool.new(:logger => @logger, :size => options[:pool_size]))
  }
end

Instance Method Details

#disposeObject



36
37
38
39
40
# File 'lib/workers/bucket_scheduler.rb', line 36

def dispose
  @schedulers.each { |s| s.dispose }

  nil
end

#schedule(timer) ⇒ Object



18
19
20
21
22
# File 'lib/workers/bucket_scheduler.rb', line 18

def schedule(timer)
  @schedulers[timer.hash % @options[:bucket_size]].schedule(timer)

  nil
end

#unschedule(timer) ⇒ Object



24
25
26
27
28
# File 'lib/workers/bucket_scheduler.rb', line 24

def unschedule(timer)
  @schedulers[timer.hash % @options[:bucket_size]].unschedule(timer)

  nil
end

#wakeupObject



30
31
32
33
34
# File 'lib/workers/bucket_scheduler.rb', line 30

def wakeup
  @schedulers.each { |s| s.wakeup }

  nil
end