Class: Tumugi::Task
Instance Attribute Summary collapse
Instance Method Summary
collapse
#target
#list
#configure, included, #validate_params
Constructor Details
#initialize ⇒ Task
Returns a new instance of Task.
13
14
15
16
|
# File 'lib/tumugi/task.rb', line 13
def initialize
super()
@state = :pending
end
|
Instance Attribute Details
#state ⇒ Object
:pending, :running, :completed, :skipped
11
12
13
|
# File 'lib/tumugi/task.rb', line 11
def state
@state
end
|
Instance Method Details
#_output ⇒ Object
88
89
90
|
# File 'lib/tumugi/task.rb', line 88
def _output
@_output ||= output
end
|
#_requires ⇒ Object
Following methods are internal use only
84
85
86
|
# File 'lib/tumugi/task.rb', line 84
def _requires
@_requires ||= requires
end
|
#completed? ⇒ Boolean
69
70
71
72
73
74
75
76
|
# File 'lib/tumugi/task.rb', line 69
def completed?
outputs = list(output)
if outputs.empty?
@state == :completed || @state == :skipped
else
outputs.all?(&:exist?)
end
end
|
#eql?(other) ⇒ Boolean
26
27
28
|
# File 'lib/tumugi/task.rb', line 26
def eql?(other)
self.hash == other.hash
end
|
#hash ⇒ Object
30
31
32
|
# File 'lib/tumugi/task.rb', line 30
def hash
self.id.hash
end
|
#id ⇒ Object
18
19
20
|
# File 'lib/tumugi/task.rb', line 18
def id
@id ||= self.class.name
end
|
#id=(s) ⇒ Object
22
23
24
|
# File 'lib/tumugi/task.rb', line 22
def id=(s)
@id = s
end
|
51
52
53
|
# File 'lib/tumugi/task.rb', line 51
def input
@input ||= _input
end
|
#instance ⇒ Object
34
35
36
|
# File 'lib/tumugi/task.rb', line 34
def instance
self
end
|
#log(msg) ⇒ Object
42
43
44
|
# File 'lib/tumugi/task.rb', line 42
def log(msg)
logger.info(msg)
end
|
#logger ⇒ Object
38
39
40
|
# File 'lib/tumugi/task.rb', line 38
def logger
@logger ||= Tumugi.logger
end
|
#output ⇒ Object
If you need to define output of task to skip alredy done task, override in subclass. If not, a task run always.
57
58
59
|
# File 'lib/tumugi/task.rb', line 57
def output
[]
end
|
#ready? ⇒ Boolean
65
66
67
|
# File 'lib/tumugi/task.rb', line 65
def ready?
list(_requires).all? { |t| t.instance.completed? }
end
|
#requires ⇒ Object
If you need to define task dependencies, override in subclass
47
48
49
|
# File 'lib/tumugi/task.rb', line 47
def requires
[]
end
|
#requires_failed? ⇒ Boolean
78
79
80
|
# File 'lib/tumugi/task.rb', line 78
def requires_failed?
list(_requires).any? { |t| t.instance.state == :failed || t.instance.state == :requires_failed }
end
|
#run ⇒ Object
61
62
63
|
# File 'lib/tumugi/task.rb', line 61
def run
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
end
|