Class: Tumugi::Task

Inherits:
Object
  • Object
show all
Includes:
Mixin::Listable, Mixin::Parameterizable, Mixin::TaskHelper
Defined in:
lib/tumugi/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::TaskHelper

#target

Methods included from Mixin::Listable

#list

Methods included from Mixin::Parameterizable

#configure, included, #validate_params

Constructor Details

#initializeTask

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

#stateObject

:pending, :running, :completed, :skipped



11
12
13
# File 'lib/tumugi/task.rb', line 11

def state
  @state
end

Instance Method Details

#_outputObject



88
89
90
# File 'lib/tumugi/task.rb', line 88

def _output
  @_output ||= output
end

#_requiresObject

Following methods are internal use only



84
85
86
# File 'lib/tumugi/task.rb', line 84

def _requires
  @_requires ||= requires
end

#completed?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


26
27
28
# File 'lib/tumugi/task.rb', line 26

def eql?(other)
  self.hash == other.hash
end

#hashObject



30
31
32
# File 'lib/tumugi/task.rb', line 30

def hash
  self.id.hash
end

#idObject



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

#inputObject



51
52
53
# File 'lib/tumugi/task.rb', line 51

def input
  @input ||= _input
end

#instanceObject



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

#loggerObject



38
39
40
# File 'lib/tumugi/task.rb', line 38

def logger
  @logger ||= Tumugi.logger
end

#outputObject

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

Returns:

  • (Boolean)


65
66
67
# File 'lib/tumugi/task.rb', line 65

def ready?
  list(_requires).all? { |t| t.instance.completed? }
end

#requiresObject

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

Returns:

  • (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

#runObject

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/tumugi/task.rb', line 61

def run
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
end