Class: Maxwell::Agent::Scheduler

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/maxwell/agent/scheduler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Scheduler

Returns a new instance of Scheduler.



8
9
10
11
12
# File 'lib/maxwell/agent/scheduler.rb', line 8

def initialize(opts={})
  @work_schedule ||= opts.fetch(:work_schedule)
  @evented_worker ||= opts.fetch(:evented_worker)
  @worker ||= opts.fetch(:worker)
end

Instance Attribute Details

#evented_workerObject (readonly)

Returns the value of attribute evented_worker.



6
7
8
# File 'lib/maxwell/agent/scheduler.rb', line 6

def evented_worker
  @evented_worker
end

#worderObject (readonly)

Returns the value of attribute worder.



6
7
8
# File 'lib/maxwell/agent/scheduler.rb', line 6

def worder
  @worder
end

#work_scheduleObject (readonly)

Returns the value of attribute work_schedule.



6
7
8
# File 'lib/maxwell/agent/scheduler.rb', line 6

def work_schedule
  @work_schedule
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
# File 'lib/maxwell/agent/scheduler.rb', line 14

def run
  set_links
  loop do
    sleep Agent.configuration.work_poll
    schedule_work
  end
end

#schedule_workObject



22
23
24
25
26
27
28
29
30
# File 'lib/maxwell/agent/scheduler.rb', line 22

def schedule_work
  if work = work_schedule.get
    if work.evented?
      evented_worker.async.perform(work)
    else
      worker.async.perform(work)
    end
  end
end