Sha256: d00a11820d25deec1f09214781b2ed031e677d60cfb6be3e589d361e480d43a7

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Workarea
  module Admin
    class CircuitsViewModel < ApplicationViewModel
      delegate :each, to: :all

      private

        def all
          @all ||= circuits.zip(circuits_broken_until, circuits_timeline).map do |circuit, broken_until, timeline|
            CircuitViewModel.new(
              circuit,
              broken_until: broken_until,
              timeline: timeline
            )
          end
        end

        def circuits
          @circuits ||= CircuitBreaker.config.circuits.map do |name, options|
            CircuitBreaker::Circuit.new(name, options)
          end
        end

        def circuits_timeline
          @circuits_timeline ||= CircuitBreaker.redis.with do |redis|
            redis.pipelined do
              circuits.each do |circuit|
                redis.zrange(circuit.redis_failure_set_key, 0, -1, with_scores: true)
              end
            end
          end
        end

        def circuits_broken_until
          @circuits_broken_until ||= CircuitBreaker.redis.with do |redis|
            redis.mget(circuits.map(&:redis_broken_key))
          end
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-circuit_breaker-1.0.3 app/view_models/workarea/admin/circuits_view_model.rb