Class: Rukawa::Job

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

Instance Attribute Summary collapse

Attributes inherited from AbstractJob

#parent_job_net

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractJob

add_skip_rule, description, #elapsed_time_from, #formatted_elapsed_time_from, #inspect, #name, set_description, #skip?

Constructor Details

#initialize(parent_job_net, variables) ⇒ Job

Returns a new instance of Job.



89
90
91
92
93
94
95
96
97
# File 'lib/rukawa/job.rb', line 89

def initialize(parent_job_net, variables)
  @parent_job_net = parent_job_net
  @variables = variables
  @in_comings = Set.new
  @out_goings = Set.new
  @retry_count = 0
  @retry_wait = 1
  set_state(:waiting)
end

Instance Attribute Details

#finished_atObject (readonly)

Returns the value of attribute finished_at.



24
25
26
# File 'lib/rukawa/job.rb', line 24

def finished_at
  @finished_at
end

#in_comingsObject

Returns the value of attribute in_comings.



23
24
25
# File 'lib/rukawa/job.rb', line 23

def in_comings
  @in_comings
end

#out_goingsObject

Returns the value of attribute out_goings.



23
24
25
# File 'lib/rukawa/job.rb', line 23

def out_goings
  @out_goings
end

#started_atObject (readonly)

Returns the value of attribute started_at.



24
25
26
# File 'lib/rukawa/job.rb', line 24

def started_at
  @started_at
end

#stateObject (readonly)

Returns the value of attribute state.



24
25
26
# File 'lib/rukawa/job.rb', line 24

def state
  @state
end

#variablesObject (readonly)

Returns the value of attribute variables.



24
25
26
# File 'lib/rukawa/job.rb', line 24

def variables
  @variables
end

Class Method Details

.after_fail(*args, **options, &block) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/rukawa/job.rb', line 61

def after_fail(*args, **options, &block)
  options[:prepend] = true
  conditional = ActiveSupport::Callbacks::Conditionals::Value.new { |v|
    v != false
  }
  options[:if] = Array(options[:if]) << conditional
  set_callback :fail, :after, *args, **options, &block
end

.after_run(*args, **options, &block) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/rukawa/job.rb', line 52

def after_run(*args, **options, &block)
  options[:prepend] = true
  conditional = ActiveSupport::Callbacks::Conditionals::Value.new { |v|
    v != false
  }
  options[:if] = Array(options[:if]) << conditional
  set_callback :run, :after, *args, **options, &block
end

.around_run(*args, **options, &block) ⇒ Object



70
71
72
# File 'lib/rukawa/job.rb', line 70

def around_run(*args, **options, &block)
  set_callback :run, :around, *args, **options, &block
end

.before_run(*args, **options, &block) ⇒ Object



48
49
50
# File 'lib/rukawa/job.rb', line 48

def before_run(*args, **options, &block)
  set_callback :run, :before, *args, **options, &block
end

.set_dependency_type(name) ⇒ Object



40
41
42
# File 'lib/rukawa/job.rb', line 40

def set_dependency_type(name)
  self.dependency_type = Rukawa::Dependency.get(name)
end

.set_resource_count(count) ⇒ Object



44
45
46
# File 'lib/rukawa/job.rb', line 44

def set_resource_count(count)
  self.resource_count = count
end

.set_retryable(limit: 8, type: nil, wait: nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/rukawa/job.rb', line 33

def set_retryable(limit: 8, type: nil, wait: nil)
  self.retryable = true
  self.retry_limit = limit
  self.retry_exception_type = type
  self.retry_wait = wait
end

Instance Method Details

#dataflowObject



111
112
113
114
115
116
117
118
119
# File 'lib/rukawa/job.rb', line 111

def dataflow
  return @dataflow if @dataflow
  return @dataflow = bypass_dataflow if @state.bypassed?

  @dataflow = Concurrent.dataflow_with(Rukawa.executor, *depend_dataflows) do |*results|
    do_run(*results)
    @state
  end
end

#jobs_as_fromObject Also known as: jobs_as_to



145
146
147
# File 'lib/rukawa/job.rb', line 145

def jobs_as_from
  [self]
end

#leaf?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/rukawa/job.rb', line 107

def leaf?
  out_goings.select { |edge| edge.cluster == @parent_job_net }.empty?
end

#root?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/rukawa/job.rb', line 103

def root?
  in_comings.select { |edge| edge.cluster == @parent_job_net }.empty?
end

#runObject



121
122
# File 'lib/rukawa/job.rb', line 121

def run
end

#set_state(name) ⇒ Object



99
100
101
# File 'lib/rukawa/job.rb', line 99

def set_state(name)
  @state = Rukawa::State.get(name)
end

#to_dot_defObject



150
151
152
153
154
155
156
# File 'lib/rukawa/job.rb', line 150

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