Class: IntelligentState

Inherits:
Object
  • Object
show all
Defined in:
lib/filestack/utils/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIntelligentState

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_typeObject

Returns the value of attribute error_type



12
13
14
# File 'lib/filestack/utils/utils.rb', line 12

def error_type
  @error_type
end

#offsetObject

Returns the value of attribute offset



12
13
14
# File 'lib/filestack/utils/utils.rb', line 12

def offset
  @offset
end

#okObject

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_retryObject



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/filestack/utils/utils.rb', line 23

def alive?
  @alive
end

#backoffObject



32
33
34
# File 'lib/filestack/utils/utils.rb', line 32

def backoff
  @backoff = 2 ** retries
end

#next_offsetObject



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

#resetObject



42
43
44
# File 'lib/filestack/utils/utils.rb', line 42

def reset
  @retries = 0
end