Class: Configuration::SourceFailover

Inherits:
Scope
  • Object
show all
Includes:
ClassLogging
Defined in:
lib/httpimagestore/configuration/source_failover.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Scope

#initialize, node_parsers, #parse, register_node_parser

Constructor Details

This class inherits a constructor from Configuration::Scope

Class Method Details

.match(node) ⇒ Object



17
18
19
# File 'lib/httpimagestore/configuration/source_failover.rb', line 17

def self.match(node)
	node.name == 'source_failover'
end

.parse(configuration, node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/httpimagestore/configuration/source_failover.rb', line 21

def self.parse(configuration, node)
	# support only sources
	handler_configuration = Struct.new(
		:global,
		:sources
	).new
	handler_configuration.global = configuration.global
	handler_configuration.sources = []

	failover = self.new(handler_configuration)
	configuration.sources << failover
	failover.parse(node)
end

Instance Method Details

#realize(request_state) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/httpimagestore/configuration/source_failover.rb', line 35

def realize(request_state)
	errors = []
	@configuration.sources.each do |source|
		begin
			log.debug "trying source: #{source}"
			return source.realize(request_state) unless source.respond_to? :excluded? and source.excluded?(request_state)
		rescue => error
			errors << error
			log.warn "source #{source} failed; trying next source", error
		end
	end
	log.error "all sources: #{@configuration.sources.map(&:to_s).join(', ')} failed; giving up"
	raise SourceFailoverAllFailedError.new(@configuration.sources.to_a, errors)
end