Class: Rukawa::Job

Inherits:
AbstractJob show all
Defined in:
lib/rukawa/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractJob

add_skip_rule, #name, #skip?, skip_rules, #skip_rules

Constructor Details

#initialize(job_net) ⇒ Job

Returns a new instance of Job.



9
10
11
12
13
14
# File 'lib/rukawa/job.rb', line 9

def initialize(job_net)
  @job_net = job_net
  @in_comings = Set.new
  @out_goings = Set.new
  set_state(:waiting)
end

Instance Attribute Details

#in_comingsObject

Returns the value of attribute in_comings.



6
7
8
# File 'lib/rukawa/job.rb', line 6

def in_comings
  @in_comings
end

#out_goingsObject

Returns the value of attribute out_goings.



6
7
8
# File 'lib/rukawa/job.rb', line 6

def out_goings
  @out_goings
end

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/rukawa/job.rb', line 7

def state
  @state
end

Instance Method Details

#dataflowObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rukawa/job.rb', line 24

def dataflow
  return @dataflow if @dataflow

  @dataflow = Concurrent.dataflow_with(Rukawa.executor, *depend_dataflows) do |*results|
    begin
      raise DependentJobFailure unless results.all? { |r| !r.nil? }

      if skip? || @job_net.skip? || results.any? { |r| r == Rukawa::State.get(:skipped) }
        Rukawa.logger.info("Skip #{self.class}")
        set_state(:skipped)
      else
        Rukawa.logger.info("Start #{self.class}")
        set_state(:running)
        run
        Rukawa.logger.info("Finish #{self.class}")
        set_state(:finished)
      end
    rescue => e
      Rukawa.logger.error("Error #{self.class} by #{e}")
      set_state(:error)
      raise
    end

    @state
  end
end

#leaf?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rukawa/job.rb', line 20

def leaf?
  out_goings.empty?
end

#nodes_as_fromObject Also known as: nodes_as_to



54
55
56
# File 'lib/rukawa/job.rb', line 54

def nodes_as_from
  [self]
end

#root?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rukawa/job.rb', line 16

def root?
  in_comings.empty?
end

#runObject



51
52
# File 'lib/rukawa/job.rb', line 51

def run
end

#to_dot_defObject



59
60
61
62
63
64
65
# File 'lib/rukawa/job.rb', line 59

def to_dot_def
  if state == Rukawa::State::Waiting
    ""
  else
    "#{name} [color = #{state.color}];\n" unless state == Rukawa::State::Waiting
  end
end