module Maxwell::Agent::Work

Public Class Methods

load(json) click to toggle source
# File lib/maxwell/agent/work.rb, line 6
def self.load(json)
  Agent::Host::Service::Serializer.deserialize(json)
end

Public Instance Methods

evented?() click to toggle source
# File lib/maxwell/agent/work.rb, line 35
def evented?
  work_class.work_type == :evented
end
expected_next_run() click to toggle source
# File lib/maxwell/agent/work.rb, line 19
def expected_next_run
  case
    when perform_at               then perform_at + last_run.to_i
    when (last_run && frequency)  then last_run + frequency
    else                          Time.new(0)
  end
end
generate_rank() click to toggle source
# File lib/maxwell/agent/work.rb, line 27
def generate_rank
  expected_next_run.to_i
end
perform() click to toggle source
# File lib/maxwell/agent/work.rb, line 31
def perform
  work_class.perform(*arguments)
end
verify_required_attributes!() click to toggle source
# File lib/maxwell/agent/work.rb, line 39
def verify_required_attributes!
  case
    when work_class.nil? then raise MissingRequiredAttributeError
  end
end
work_now?() click to toggle source
# File lib/maxwell/agent/work.rb, line 11
def work_now?
  case
    when perform_at then perform_at_less_than_now?
    when frequency  then stale?
    else                 true
  end
end

Private Instance Methods

perform_at_less_than_now?() click to toggle source
# File lib/maxwell/agent/work.rb, line 55
def perform_at_less_than_now?
  return perform_at.find {|at| at <= Time.now } if perform_at.respond_to? :each
  perform_at <= Time.now
end
set_default_attrs!() click to toggle source
# File lib/maxwell/agent/work.rb, line 46
def set_default_attrs!
  self.last_run ||= Time.new(0)
  self.frequency ||= 30.minutes
end
stale?() click to toggle source
# File lib/maxwell/agent/work.rb, line 60
def stale?
  time_since_last_run >= frequency
end
time_since_last_run() click to toggle source
# File lib/maxwell/agent/work.rb, line 51
def time_since_last_run
  Time.now.to_i - last_run.to_i
end