Class: Rub2::Job
- Inherits:
-
Object
- Object
- Rub2::Job
- Defined in:
- lib/rub2.rb
Instance Attribute Summary collapse
-
#array_id ⇒ Object
readonly
Returns the value of attribute array_id.
-
#died_at ⇒ Object
readonly
Returns the value of attribute died_at.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
Instance Method Summary collapse
- #dead_end?(t) ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(parent_id, array_id, max_retry) ⇒ Job
constructor
A new instance of Job.
- #inspect ⇒ Object
- #job_id ⇒ Object
- #need_retry? ⇒ Boolean
- #set_dead_time(t) ⇒ Object
- #set_exit_code(exit_code) ⇒ Object
- #set_resubmit_id(new_parent_id) ⇒ Object
- #succeeded? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(parent_id, array_id, max_retry) ⇒ Job
Returns a new instance of Job.
125 126 127 128 129 130 131 132 133 |
# File 'lib/rub2.rb', line 125 def initialize(parent_id, array_id, max_retry) @parent_id = parent_id @array_id = array_id @max_retry = max_retry raise "negative max_retry" if max_retry < 0 @exit_code = nil @retry_count = 0 @died_at = nil end |
Instance Attribute Details
#array_id ⇒ Object (readonly)
Returns the value of attribute array_id.
123 124 125 |
# File 'lib/rub2.rb', line 123 def array_id @array_id end |
#died_at ⇒ Object (readonly)
Returns the value of attribute died_at.
123 124 125 |
# File 'lib/rub2.rb', line 123 def died_at @died_at end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
123 124 125 |
# File 'lib/rub2.rb', line 123 def exit_code @exit_code end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
123 124 125 |
# File 'lib/rub2.rb', line 123 def parent_id @parent_id end |
Instance Method Details
#dead_end?(t) ⇒ Boolean
162 163 164 165 |
# File 'lib/rub2.rb', line 162 def dead_end?(t) return false if @died_at.nil? return (t - @died_at) > 60.0 # daed job, maybe end |
#finished? ⇒ Boolean
135 136 137 138 |
# File 'lib/rub2.rb', line 135 def finished? return false if @exit_code.nil? return (not need_retry?) end |
#inspect ⇒ Object
178 179 180 |
# File 'lib/rub2.rb', line 178 def inspect "#<Job: @parent_id=#{@parent_id}, @array_id=#{@array_id}, @exit_code=#{@exit_code}, @retry_count=#{@retry_count}, @max_retry=#{@max_retry}, @died_at=#{@died_at}>" end |
#job_id ⇒ Object
150 151 152 |
# File 'lib/rub2.rb', line 150 def job_id return "#{@parent_id}[#{@array_id}]" end |
#need_retry? ⇒ Boolean
144 145 146 147 148 |
# File 'lib/rub2.rb', line 144 def need_retry? return false if @exit_code.nil? return false if succeeded? return @retry_count < @max_retry end |
#set_dead_time(t) ⇒ Object
167 168 169 |
# File 'lib/rub2.rb', line 167 def set_dead_time(t) @died_at = t end |
#set_exit_code(exit_code) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/rub2.rb', line 154 def set_exit_code(exit_code) unless @exit_code.nil? Rub2.putlog("warn: already assigned exit_code #{self} #{@exit_code} -> #{exit_code}") end @exit_code = exit_code @died_at = nil end |
#set_resubmit_id(new_parent_id) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/rub2.rb', line 171 def set_resubmit_id(new_parent_id) @parent_id = new_parent_id @exit_code = nil @died_at = nil @retry_count += 1 end |
#succeeded? ⇒ Boolean
140 141 142 |
# File 'lib/rub2.rb', line 140 def succeeded? return @exit_code == 0 end |
#to_s ⇒ Object
182 183 184 |
# File 'lib/rub2.rb', line 182 def to_s return job_id end |