Top Level Namespace

Defined Under Namespace

Modules: Stately, StatelyCode, StatelyDB

Constant Summary collapse

LOGGER =
Logger.new($stdout)

Instance Method Summary collapse

Instance Method Details

#backoff(attempt, base_backoff) ⇒ Float

backoff returns a duration to wait before retrying a request. ‘attempt` is the current attempt number, starting from 0 (e.g. the first attempt is 0, then 1, then 2…).

Parameters:

  • attempt (Integer)

    The current attempt number

  • base_backoff (Float)

    The base backoff time in seconds

Returns:

  • (Float)

    The duration in seconds to wait before retrying



116
117
118
119
120
121
122
123
# File 'lib/common/auth/token_fetcher.rb', line 116

def backoff(attempt, base_backoff)
  # Double the base backoff time per attempt, starting with 1
  exp = 2**attempt
  # Add a full jitter to the backoff time, from no wait to 100% of the exponential backoff.
  # See https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
  jitter = rand
  (exp * jitter * base_backoff)
end

#build_filters(item_types: [], cel_filters: []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/common/build_filters.rb', line 5

def build_filters(item_types: [], cel_filters: [])
  filters = item_types.map do |item_type|
    Stately::Db::FilterCondition.new(item_type: item_type.respond_to?(:name) ? item_type.name.split("::").last : item_type)
  end
  filters += cel_filters.map do |filter|
    Stately::Db::FilterCondition.new(
      cel_expression: {
        item_type: filter[0].respond_to?(:name) ? filter[0].name.split("::").last : filter[0],
        expression: filter[1]
      }
    )
  end
  filters
end

#safe_yield(&block) ⇒ Object



20
21
22
23
24
# File 'lib/common/error_interceptor.rb', line 20

def safe_yield(*, &block)
  block.call(*)
rescue Exception => e
  raise StatelyDB::Error.from(e)
end

#safe_yield_stream(stream, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/common/error_interceptor.rb', line 26

def safe_yield_stream(stream, &block)
  stream.each do |msg|
    safe_yield(msg, &block)
  end
rescue Exception => e
  raise StatelyDB::Error.from(e)
end