Sha256: 4df2698e323e37ca78abe395a9961905b31e31959c8de4bd57aa9410343dc005

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

module Freno
  class Throttler

    # A Mapper is any object that responds to `call`, by receiving a context
    # object and returning a list of strings, each of which corresponds to the
    # store_name that will be checked in freno.
    #
    # See https://github.com/github/freno/blob/master/doc/http.md#client-requests
    # for more context.
    #
    # As an example we could use a mapper that will receive as a context a set
    # of [table, shard_id] tuples, and could return the list of all the stores
    # where that shards exist.
    #
    module Mapper

      # The Identity mapper is the one used by default in the Throttler.
      #
      # It works by informing the throttler to check exact same stores that it
      # receives as context, without any translation.
      #
      # Let's use the following throttler, which uses Mapper::Identity
      # implicitly.
      #
      # ```ruby
      # throttler = Throttler.new(client: freno_client, app: :my_app)
      # data.find_in_batches do |batch|
      #   throttler.throttle([:mysqla, :mysqlb]) do
      #     update(batch)
      #   end
      # end
      # ```
      #
      # Before each call to `update(batch)` the throttler will call freno to
      # check the health of `mysqla` and `mysqlb`. And sleep if any of them is
      # not ok.
      #
      class Identity
        def self.call(context)
          Array(context)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
freno-client-0.8.1 lib/freno/throttler/mapper.rb
freno-client-0.8.0 lib/freno/throttler/mapper.rb
freno-client-0.7.0 lib/freno/throttler/mapper.rb
freno-client-0.6.0 lib/freno/throttler/mapper.rb