Module: Maxwell::Agent::Work

Included in:
Host::Service
Defined in:
lib/maxwell/agent/work.rb

Defined Under Namespace

Classes: MissingRequiredAttributeError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(json) ⇒ Object



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

def self.load(json)
  Agent::Host::Service::Serializer.deserialize(json)
end

Instance Method Details

#evented?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/maxwell/agent/work.rb', line 35

def evented?
  work_class.work_type == :evented
end

#expected_next_runObject



19
20
21
22
23
24
25
# 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_rankObject



27
28
29
# File 'lib/maxwell/agent/work.rb', line 27

def generate_rank
  expected_next_run.to_i
end

#performObject



31
32
33
# File 'lib/maxwell/agent/work.rb', line 31

def perform
  work_class.perform(*arguments)
end

#verify_required_attributes!Object



39
40
41
42
43
# File 'lib/maxwell/agent/work.rb', line 39

def verify_required_attributes!
  case
    when work_class.nil? then raise MissingRequiredAttributeError
  end
end

#work_now?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# 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