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
13 14 15 16 17 18 19 20 21 |
# File 'lib/filestack/utils/utils.rb', line 13 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
12 13 14 |
# File 'lib/filestack/utils/utils.rb', line 12 def error_type @error_type end |
#offset ⇒ Object
Returns the value of attribute offset
12 13 14 |
# File 'lib/filestack/utils/utils.rb', line 12 def offset @offset end |
#ok ⇒ Object
Returns the value of attribute ok
12 13 14 |
# File 'lib/filestack/utils/utils.rb', line 12 def ok @ok end |
Instance Method Details
#add_retry ⇒ Object
27 28 29 30 |
# File 'lib/filestack/utils/utils.rb', line 27 def add_retry @retries += 1 @alive = false if @retries >= 5 end |
#alive? ⇒ Boolean
23 24 25 |
# File 'lib/filestack/utils/utils.rb', line 23 def alive? @alive end |
#backoff ⇒ Object
32 33 34 |
# File 'lib/filestack/utils/utils.rb', line 32 def backoff @backoff = 2 ** retries end |
#next_offset ⇒ Object
36 37 38 39 40 |
# File 'lib/filestack/utils/utils.rb', line 36 def next_offset current_offset = @offset_sizes[@offset_index] @offset_index += 1 return current_offset end |
#reset ⇒ Object
42 43 44 |
# File 'lib/filestack/utils/utils.rb', line 42 def reset @retries = 0 end |