Class: Cumulus::SQS::QueueConfig
- Inherits:
-
Object
- Object
- Cumulus::SQS::QueueConfig
- Defined in:
- lib/sqs/models/QueueConfig.rb
Overview
Public: An object representing configuration for a queue
Instance Attribute Summary collapse
-
#dead_letter ⇒ Object
readonly
Returns the value of attribute dead_letter.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#max_message_size ⇒ Object
readonly
Returns the value of attribute max_message_size.
-
#message_retention ⇒ Object
readonly
Returns the value of attribute message_retention.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#receive_wait_time ⇒ Object
readonly
Returns the value of attribute receive_wait_time.
-
#visibility_timeout ⇒ Object
readonly
Returns the value of attribute visibility_timeout.
Instance Method Summary collapse
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(name, json = nil) ⇒ QueueConfig
constructor
Public: Constructor.
-
#populate!(attributes) ⇒ Object
Public: Populate a config object with AWS configuration.
- #to_hash ⇒ Object
Constructor Details
#initialize(name, json = nil) ⇒ QueueConfig
Public: Constructor
json - a hash containing the JSON configuration for the queue
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sqs/models/QueueConfig.rb', line 24 def initialize(name, json = nil) @name = name if !json.nil? @delay = json["delay"] @max_message_size = json["max-message-size"] @message_retention = json["message-retention"] @policy = json["policy"] @receive_wait_time = json["receive-wait-time"] @visibility_timeout = json["visibility-timeout"] @dead_letter = if json["dead-letter"] then DeadLetterConfig.new(json["dead-letter"]) end end end |
Instance Attribute Details
#dead_letter ⇒ Object (readonly)
Returns the value of attribute dead_letter.
19 20 21 |
# File 'lib/sqs/models/QueueConfig.rb', line 19 def dead_letter @dead_letter end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
13 14 15 |
# File 'lib/sqs/models/QueueConfig.rb', line 13 def delay @delay end |
#max_message_size ⇒ Object (readonly)
Returns the value of attribute max_message_size.
14 15 16 |
# File 'lib/sqs/models/QueueConfig.rb', line 14 def @max_message_size end |
#message_retention ⇒ Object (readonly)
Returns the value of attribute message_retention.
15 16 17 |
# File 'lib/sqs/models/QueueConfig.rb', line 15 def @message_retention end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/sqs/models/QueueConfig.rb', line 12 def name @name end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
16 17 18 |
# File 'lib/sqs/models/QueueConfig.rb', line 16 def policy @policy end |
#receive_wait_time ⇒ Object (readonly)
Returns the value of attribute receive_wait_time.
17 18 19 |
# File 'lib/sqs/models/QueueConfig.rb', line 17 def receive_wait_time @receive_wait_time end |
#visibility_timeout ⇒ Object (readonly)
Returns the value of attribute visibility_timeout.
18 19 20 |
# File 'lib/sqs/models/QueueConfig.rb', line 18 def visibility_timeout @visibility_timeout end |
Instance Method Details
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS
aws - the AWS resource
Returns an array of the QueueDiffs that were found
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sqs/models/QueueConfig.rb', line 74 def diff(aws) diffs = [] if @delay != aws.delay diffs << QueueDiff.new(QueueChange::DELAY, aws.delay, @delay) end if @max_message_size != aws. diffs << QueueDiff.new(QueueChange::MESSAGE_SIZE, aws., @max_message_size) end if @message_retention != aws. diffs << QueueDiff.new(QueueChange::MESSAGE_RETENTION, aws., @message_retention) end if @receive_wait_time != aws.receive_wait_time diffs << QueueDiff.new(QueueChange::RECEIVE_WAIT, aws.receive_wait_time, @receive_wait_time) end if @visibility_timeout != aws.visibility_timeout diffs << QueueDiff.new(QueueChange::VISIBILITY, aws.visibility_timeout, @visibility_timeout) end aws_dead_letter = aws.dead_letter || DeadLetterConfig.new() local_dead_letter = @dead_letter || DeadLetterConfig.new() dead_diffs = local_dead_letter.diff(aws_dead_letter) if !dead_diffs.empty? diffs << QueueDiff.new(QueueChange::DEAD, aws_dead_letter, local_dead_letter, dead_diffs) end aws_policy = SQS::queue_policy(@name) local_policy = if @policy then Loader.policy(@policy) end if local_policy != aws_policy diffs << QueueDiff.new(QueueChange::POLICY, aws_policy, local_policy) end diffs end |
#populate!(attributes) ⇒ Object
Public: Populate a config object with AWS configuration
attributes - the queue attributes in AWS
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sqs/models/QueueConfig.rb', line 52 def populate!(attributes) @delay = if attributes["DelaySeconds"] then attributes["DelaySeconds"].to_i end @max_message_size = if attributes["MaximumMessageSize"] then attributes["MaximumMessageSize"].to_i end @message_retention = if attributes["MessageRetentionPeriod"] then attributes["MessageRetentionPeriod"].to_i end @receive_wait_time = if attributes["ReceiveMessageWaitTimeSeconds"] then attributes["ReceiveMessageWaitTimeSeconds"].to_i end @visibility_timeout = if attributes["VisibilityTimeout"] then attributes["VisibilityTimeout"].to_i end @dead_letter = if attributes["RedrivePolicy"] then DeadLetterConfig.new().populate!(attributes["RedrivePolicy"]) end # Policy is handled specially because we store them in a separate file locally. # For migrating we assume the policy is the same as the queue name, otherwise this # attribute is not used from AWS config @policy = if attributes["Policy"] then @name end self end |
#to_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sqs/models/QueueConfig.rb', line 37 def to_hash { "delay" => @delay, "max-message-size" => @max_message_size, "message-retention" => @message_retention, "policy" => @policy, "receive-wait-time" => @receive_wait_time, "visibility-timeout" => @visibility_timeout, "dead-letter" => if @dead_letter then @dead_letter.to_hash end, }.reject { |k, v| v.nil? } end |