Module: Maxwell::Agent::Work
Defined Under Namespace
Classes: MissingRequiredAttributeError
Constant Summary
collapse
- REQUIRED_ATTRIBUTES =
[:name, :work_class]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_json(json) ⇒ Object
21
22
23
|
# File 'lib/maxwell/agent/work.rb', line 21
def self.from_json(json)
JSON.parse(json)
end
|
.included(base) ⇒ Object
11
12
13
|
# File 'lib/maxwell/agent/work.rb', line 11
def self.included(base)
base.send(:include, DynamicAttributes)
end
|
.load(json) ⇒ Object
16
17
18
19
|
# File 'lib/maxwell/agent/work.rb', line 16
def self.load(json)
work = from_json(json)
work.delete('klass').constantize.new.load(work)
end
|
Instance Method Details
#expected_next_run ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/maxwell/agent/work.rb', line 62
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
end
end
|
#frequency ⇒ Object
50
51
52
|
# File 'lib/maxwell/agent/work.rb', line 50
def frequency
super || self.frequency = 30.minutes
end
|
#generate_rank ⇒ Object
70
71
72
|
# File 'lib/maxwell/agent/work.rb', line 70
def generate_rank
expected_next_run.to_i
end
|
#last_run ⇒ Object
46
47
48
|
# File 'lib/maxwell/agent/work.rb', line 46
def last_run
super || self.last_run = Time.new(0)
end
|
#load(attrs = {}) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/maxwell/agent/work.rb', line 25
def load(attrs={})
attrs.each do |key, value|
send("#{key}=", value )
end
self
end
|
74
75
76
|
# File 'lib/maxwell/agent/work.rb', line 74
def perform
work_class.perform(*arguments)
end
|
#to_json ⇒ Object
32
33
34
35
36
37
|
# File 'lib/maxwell/agent/work.rb', line 32
def to_json
verify_required_attributes!
instance_variables.inject({}) do |result, attr|
result.merge(attr.to_s.gsub('@','') => instance_variable_get(attr))
end.merge({klass: self.class}).to_json
end
|
#verify_required_attributes! ⇒ Object
#work_now? ⇒ Boolean
54
55
56
57
58
59
60
|
# File 'lib/maxwell/agent/work.rb', line 54
def work_now?
case
when perform_at then perform_at_less_than_now?
when frequency then stale?
else true
end
end
|