Class: AwsSqsMoniter::Configuration

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/aws_sqs_moniter/configuration.rb,
lib/aws_sqs_moniter/configuration/validatable.rb,
lib/aws_sqs_moniter/configuration/queue_configuration.rb,
lib/aws_sqs_moniter/configuration/redrive_policy_configuration.rb

Defined Under Namespace

Modules: Validatable Classes: QueueConfiguration, RedrivePolicyConfiguration

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

#errors, #valid?

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
# File 'lib/aws_sqs_moniter/configuration.rb', line 9

def initialize
  @queues = {}
  @queue_defaults = QueueConfiguration.new 'queue_defaults'
  @sns_protocol = @sqs_protocol = 'sqs'
end

Instance Attribute Details

#queue_defaultsObject (readonly)

Returns the value of attribute queue_defaults.



15
16
17
# File 'lib/aws_sqs_moniter/configuration.rb', line 15

def queue_defaults
  @queue_defaults
end

#sns_endpointObject (readonly)

Returns the value of attribute sns_endpoint.



15
16
17
# File 'lib/aws_sqs_moniter/configuration.rb', line 15

def sns_endpoint
  @sns_endpoint
end

#sns_protocolObject (readonly)

Returns the value of attribute sns_protocol.



15
16
17
# File 'lib/aws_sqs_moniter/configuration.rb', line 15

def sns_protocol
  @sns_protocol
end

#sqs_endpointObject (readonly)

Returns the value of attribute sqs_endpoint.



15
16
17
# File 'lib/aws_sqs_moniter/configuration.rb', line 15

def sqs_endpoint
  @sqs_endpoint
end

#sqs_protocolObject (readonly)

Returns the value of attribute sqs_protocol.



15
16
17
# File 'lib/aws_sqs_moniter/configuration.rb', line 15

def sqs_protocol
  @sqs_protocol
end

Instance Method Details

#add_queue(name) {|queue| ... } ⇒ Object

Yields:

  • (queue)


17
18
19
20
21
22
23
24
25
# File 'lib/aws_sqs_moniter/configuration.rb', line 17

def add_queue name
  environmental_name = Aws::EnvironmentalName.new(name).to_s
  fail "A queue called #{name} already exists." if @queues.key? environmental_name

  queue = QueueConfiguration.new name
  @queue_defaults.copy_onto queue
  yield queue if block_given?
  @queues[environmental_name] = queue
end

#aws_account_idObject



31
32
33
# File 'lib/aws_sqs_moniter/configuration.rb', line 31

def 
  shoryuken_config[:aws][:account_id]
end

#aws_optionsObject



27
28
29
# File 'lib/aws_sqs_moniter/configuration.rb', line 27

def aws_options
  @aws_options ||= shoryuken_config[:aws].slice :access_key_id, :region, :secret_access_key
end

#aws_regionObject



35
36
37
# File 'lib/aws_sqs_moniter/configuration.rb', line 35

def aws_region
  aws_options[:region]
end

#enable_cmb_modeObject



39
40
41
42
43
# File 'lib/aws_sqs_moniter/configuration.rb', line 39

def enable_cmb_mode
  @sns_protocol = @sqs_protocol = 'cqs'
  @sns_endpoint = shoryuken_config[:aws][:sns_endpoint]
  @sqs_endpoint = shoryuken_config[:aws][:sqs_endpoint]
end

#get_queue(environmental_name) ⇒ Object



49
50
51
# File 'lib/aws_sqs_moniter/configuration.rb', line 49

def get_queue environmental_name
  @queues[environmental_name]
end

#queuesObject



45
46
47
# File 'lib/aws_sqs_moniter/configuration.rb', line 45

def queues
  @queues.values
end

#require_workersObject



53
54
55
56
57
# File 'lib/aws_sqs_moniter/configuration.rb', line 53

def require_workers
  Dir[Rails.root + 'app' + 'workers' + '*.rb'].each do |path|
    require path
  end
end

#shoryuken_configObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/aws_sqs_moniter/configuration.rb', line 59

def shoryuken_config
  @shoryuken_config ||= begin
    YAML.load(
      ERB.new(
        IO.read(
          Rails.root + 'config' + 'shoryuken.yml')
        ).result
      ).with_indifferent_access
  end
end

#sns_optionsObject



70
71
72
# File 'lib/aws_sqs_moniter/configuration.rb', line 70

def sns_options
  aws_client_options :sns_endpoint
end

#sqs_optionsObject



74
75
76
# File 'lib/aws_sqs_moniter/configuration.rb', line 74

def sqs_options
  aws_client_options :sqs_endpoint
end

#use_aws_sqs_moniter_loggingObject



78
79
80
81
# File 'lib/aws_sqs_moniter/configuration.rb', line 78

def use_aws_sqs_moniter_logging
  require 'aws_sqs_moniter/logging'
  Shoryuken::Logging.logger = AwsSqsMoniter::Logging.logger
end

#use_typed_message_registry(dead_letter_queue_name) ⇒ Object



83
84
85
86
# File 'lib/aws_sqs_moniter/configuration.rb', line 83

def use_typed_message_registry dead_letter_queue_name
  require 'aws_sqs_moniter/worker_registries/typed_message_registry'
  Shoryuken.worker_registry = AwsSqsMoniter::WorkerRegistries::TypedMessageRegistry.new dead_letter_queue_name
end

#validateObject



88
89
90
91
92
93
# File 'lib/aws_sqs_moniter/configuration.rb', line 88

def validate
  [queue_defaults, queues].flatten.compact.each do |section|
    section.valid?
    errors.push *(section.errors)
  end
end

#validate!Object



95
96
97
98
99
# File 'lib/aws_sqs_moniter/configuration.rb', line 95

def validate!
  return if valid?

  fail %(Invalid configuration: \n\n#{errors.join("\n")}\n\n)
end