Class: Smash::CloudPowers::Synapse::Queue::Board
- Inherits:
-
Object
- Object
- Smash::CloudPowers::Synapse::Queue::Board
- Includes:
- AwsResources, Helper, Smash::CloudPowers::Synapse::Queue, Zenv
- Defined in:
- lib/cloud_powers/synapse/queue/board.rb
Overview
The Queue::Board class helps wrap up information and functionality of a Queue on SQS. It is basically just an abstraction to make using SQS simpler
Instance Attribute Summary collapse
-
#address ⇒ Object
Gives the Queue address (URL).
-
#name ⇒ Object
Returns the value of attribute name.
-
#poller ⇒ Object
Gets a QueuePoller for the Queue attached to this Board instance.
Class Method Summary collapse
-
.build(name) ⇒ Object
Builds a Queue::Board object and returns it.
-
.create!(name) ⇒ Object
Builds then Creates the Object and makes the API call to SQS to create the queue @params: name
@returns: Queue::Board with an actual queue in SQS.
Instance Method Summary collapse
-
#best_guess_address ⇒ Object
Gives a best guess at the URL that points toward this Board's Queue.
-
#create_queue! ⇒ Object
Creates an actual Queue in SQS using the standard format for a queue name (camel case) @returns: Queue::Board.
-
#destroy! ⇒ Object
Deletes an actual Queue from SQS.
-
#exists? ⇒ Boolean
Predicate method to query SQS for the queue.
-
#i_var ⇒ Object
Gives back a string representation of the instance variable for this board.
-
#initialize(name) ⇒ Board
constructor
Takes a
nameand creates a Board object. -
#message_count ⇒ Object
Gets the approximate message count for a Queue using the 'ApproximateMessageCount' attribute.
-
#pluck_message ⇒ Object
Retrieves a message from the Queue and deletes it from the Queue in SQS.
-
#save! ⇒ Object
This method creates the queue in SQS for the given Board instance It can be coupled with the #build() method in order to use a queue without making the call to create it on AWS.
-
#send_message(message) ⇒ Object
Sends the given message to the queue @params: message, which is either used as JSON or converted into it.
Methods included from Zenv
#env_vars, #file_tree_search, #i_vars, #project_root, #project_root=, #system_vars, #zfind
Methods included from Helper
#attr_map!, #called_from, #create_logger, #errors, #format_error_message, #log_file, #logger, #smart_retry, #task_path, #task_require_path, #to_camel, #to_i_var, #to_pascal, #to_ruby_file_name, #to_snake, #update_message_body, #valid_json?
Methods included from Smash::CloudPowers::Synapse::Queue
#board_name, #build_queue, #delete_queue_message, #get_queue_message_count, #pluck_queue_message, #poll, #queue_exists?, #queue_poller, #queue_search, #send_queue_message
Methods included from AwsResources
#ec2, #image, #kinesis, #region, #s3, #sns, #sqs
Methods included from Auth
Constructor Details
#initialize(name) ⇒ Board
Takes a name and creates a Board object.
The #new method is wrapped in #build() and #create!() but isn't labeled private so
#new can be used instead of build.
The Board doesn't create Queue(s) or any other API calls until it is instructed to.
@params: name
22 23 24 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 22 def initialize(name) @name = name end |
Instance Attribute Details
#address ⇒ Object
Gives the Queue address (URL). First the environment is searched, using Zenv and if nothing is
found, the best guess attempt at the correct address is used.
@returns: queue address
39 40 41 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 39 def address @address end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 13 def name @name end |
#poller ⇒ Object
Gets a QueuePoller for the Queue attached to this Board instance
89 90 91 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 89 def poller @poller end |
Class Method Details
.build(name) ⇒ Object
Builds a Queue::Board object and returns it. No API calls are sent using this method
@params: name
54 55 56 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 54 def self.build(name) new(name) end |
.create!(name) ⇒ Object
Builds then Creates the Object and makes the API call to SQS to create the queue
@params: name
61 62 63 64 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 61 def self.create!(name) built_board = build(name) built_board.create_queue! end |
Instance Method Details
#best_guess_address ⇒ Object
Gives a best guess at the URL that points toward this Board's Queue. It uses a couple params to build a standard URL for SQS. The only problem with using this last resort is you may need to use a Queue from a different region, account or name but it can be a handy catch-all for the URLs for most cases.
47 48 49 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 47 def best_guess_address "https://sqs.#{zfind(:aws_region)}.amazonaws.com/#{zfind(:account_number)}/#{@name}" end |
#create_queue! ⇒ Object
Creates an actual Queue in SQS using the standard format for a queue name (camel case) @returns: Queue::Board
68 69 70 71 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 68 def create_queue! sqs.create_queue(queue_name: to_camel(@name)) self end |
#destroy! ⇒ Object
Deletes an actual Queue from SQS
74 75 76 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 74 def destroy! sqs.delete_queue(queue_url: address) end |
#exists? ⇒ Boolean
Predicate method to query SQS for the queue
79 80 81 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 79 def exists? queue_exists?(@name) end |
#i_var ⇒ Object
32 33 34 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 32 def i_var "@#{@name}" end |
#message_count ⇒ Object
Gets the approximate message count for a Queue using the 'ApproximateMessageCount' attribute
84 85 86 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 84 def (address) end |
#pluck_message ⇒ Object
Retrieves a message from the Queue and deletes it from the Queue in SQS
94 95 96 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 94 def (@name) end |
#save! ⇒ Object
This method creates the queue in SQS for the given Board instance It can be coupled with the #build() method in order to use a queue without making the call to create it on AWS
101 102 103 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 101 def save! create_queue! end |
#send_message(message) ⇒ Object
Sends the given message to the queue @params: message, which is either used as JSON or converted into it
107 108 109 110 111 |
# File 'lib/cloud_powers/synapse/queue/board.rb', line 107 def () ( address, (valid_json?() ? : .to_json) ) end |