Class: AwsSqsMoniter::Configuration
- Inherits:
-
Object
- Object
- AwsSqsMoniter::Configuration
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
#errors, #valid?
Constructor Details
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_defaults ⇒ Object
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_endpoint ⇒ Object
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_protocol ⇒ Object
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_endpoint ⇒ Object
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_protocol ⇒ Object
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
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_id ⇒ Object
31
32
33
|
# File 'lib/aws_sqs_moniter/configuration.rb', line 31
def aws_account_id
shoryuken_config[:aws][:account_id]
end
|
#aws_options ⇒ Object
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_region ⇒ Object
35
36
37
|
# File 'lib/aws_sqs_moniter/configuration.rb', line 35
def aws_region
aws_options[:region]
end
|
#enable_cmb_mode ⇒ Object
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
|
#queues ⇒ Object
45
46
47
|
# File 'lib/aws_sqs_moniter/configuration.rb', line 45
def queues
@queues.values
end
|
#require_workers ⇒ Object
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_config ⇒ Object
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_options ⇒ Object
70
71
72
|
# File 'lib/aws_sqs_moniter/configuration.rb', line 70
def sns_options
aws_client_options :sns_endpoint
end
|
#sqs_options ⇒ Object
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_logging ⇒ Object
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
|
#validate ⇒ Object
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
|