Class: IntelligentState
- Inherits:
-
Object
- Object
- IntelligentState
- Defined in:
- lib/filestack/utils/utils.rb
Instance Attribute Summary collapse
-
#error_type ⇒ Object
Returns the value of attribute error_type.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#ok ⇒ Object
Returns the value of attribute ok.
Instance Method Summary collapse
- #add_retry ⇒ Object
- #alive? ⇒ Boolean
- #backoff ⇒ Object
-
#initialize ⇒ IntelligentState
constructor
A new instance of IntelligentState.
- #next_offset ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ IntelligentState
Returns a new instance of IntelligentState.
11 12 13 14 15 16 17 18 19 |
# File 'lib/filestack/utils/utils.rb', line 11 def initialize @offset = 524288 @ok = true @alive = true @retries = 0 @backoff = 1 @offset_index = 0 @offset_sizes = [524288, 262144, 131072, 65536, 32768] end |
Instance Attribute Details
#error_type ⇒ Object
Returns the value of attribute error_type.
10 11 12 |
# File 'lib/filestack/utils/utils.rb', line 10 def error_type @error_type end |
#offset ⇒ Object
Returns the value of attribute offset.
10 11 12 |
# File 'lib/filestack/utils/utils.rb', line 10 def offset @offset end |
#ok ⇒ Object
Returns the value of attribute ok.
10 11 12 |
# File 'lib/filestack/utils/utils.rb', line 10 def ok @ok end |
Instance Method Details
#add_retry ⇒ Object
25 26 27 28 |
# File 'lib/filestack/utils/utils.rb', line 25 def add_retry @retries += 1 @alive = false if @retries >= 5 end |
#alive? ⇒ Boolean
21 22 23 |
# File 'lib/filestack/utils/utils.rb', line 21 def alive? @alive end |
#backoff ⇒ Object
30 31 32 |
# File 'lib/filestack/utils/utils.rb', line 30 def backoff @backoff = 2 ** @retries end |
#next_offset ⇒ Object
34 35 36 37 38 |
# File 'lib/filestack/utils/utils.rb', line 34 def next_offset current_offset = @offset_sizes[@offset_index] @offset_index += 1 return current_offset end |
#reset ⇒ Object
40 41 42 |
# File 'lib/filestack/utils/utils.rb', line 40 def reset @retries = 0 end |