class Maxwell::Agent::WorkSchedule

Public Class Methods

new() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 6
def initialize
  @schedule = RedisObjects::SortedSet.new_link('work_schedule')
  @working  = RedisObjects::Set.new_link('work_schedule:working')
end

Public Instance Methods

add(work) click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 11
def add(work)
  @schedule.async.add(work.generate_rank, work)
  work
end
all() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 37
def all
  schedule.concat(working)
end
count() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 16
def count
  schedule.count
end
get() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 20
def get
  find_ready_for_work
end
put_back(work) click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 24
def put_back(work)
  @working.async.remove(work)
  add(work)
end
schedule() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 33
def schedule
  @schedule.all.map {|work| Work.load(work) }
end
working() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 29
def working
  @working.all.map {|work| Work.load(work) }
end

Private Instance Methods

find_ready_for_work() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 43
def find_ready_for_work
  work = get_work
  if work && work.work_now?
    move_to_working_queue(work)
    work
  end
end
get_work() click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 51
def get_work
  work = @schedule.first
  Work.load(work) if work
end
is_being_worked_on?(work) click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 61
def is_being_worked_on?(work)
  @working.exists?(work)
end
move_to_working_queue(work) click to toggle source
# File lib/maxwell/agent/work_schedule.rb, line 56
def move_to_working_queue(work)
  @working.async.add(work)
  @schedule.async.remove(work)
end