cloud_powers 0.2.7 → 0.2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.rdoc.mdown +180 -0
- data/Rakefile +5 -0
- data/cloud_powers.gemspec +1 -1
- data/lib/cloud_powers/auth.rb +24 -10
- data/lib/cloud_powers/aws_resources.rb +70 -114
- data/lib/cloud_powers/context.rb +66 -31
- data/lib/cloud_powers/helper.rb +36 -33
- data/lib/cloud_powers/node.rb +2 -2
- data/lib/cloud_powers/self_awareness.rb +18 -11
- data/lib/cloud_powers/synapse/broadcast/broadcast.rb +27 -9
- data/lib/cloud_powers/synapse/pipe/pipe.rb +77 -31
- data/lib/cloud_powers/synapse/queue/board.rb +78 -32
- data/lib/cloud_powers/synapse/queue/queue.rb +164 -38
- data/lib/cloud_powers/synapse/synapse.rb +7 -6
- data/lib/cloud_powers/version.rb +1 -1
- data/lib/cloud_powers/zenv.rb +11 -11
- data/lib/cloud_powers.rb +10 -0
- data/lib/stubs/aws_stubs.rb +132 -4
- metadata +4 -3
@@ -8,11 +8,14 @@ module Smash
|
|
8
8
|
|
9
9
|
# Create a Kinesis stream or wait until the stream with the given name is
|
10
10
|
# through being created.
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
11
|
+
#
|
12
|
+
# Parameters
|
13
|
+
# * name +String+
|
14
|
+
#
|
15
|
+
# Returns Boolean or nil
|
16
|
+
# * returns true or false if the request was successful or not
|
17
|
+
# * returns true if the stream has already been created
|
18
|
+
# * returns false if the stream was not created
|
16
19
|
def create_stream(name)
|
17
20
|
begin
|
18
21
|
config = stream_config(stream_name: name)
|
@@ -35,11 +38,25 @@ module Smash
|
|
35
38
|
end
|
36
39
|
|
37
40
|
# Use the KCL and LangDaemon to read from a stream
|
38
|
-
#
|
41
|
+
# Parameters stream String
|
42
|
+
#
|
43
|
+
# Notes
|
44
|
+
# This method is not implemented yet (V 0.2.7)
|
39
45
|
def flow_from_pipe(stream)
|
40
46
|
throw NotImplementedError
|
41
47
|
end
|
42
48
|
|
49
|
+
# Sends data through a Pipe. This method is used for lower throughput
|
50
|
+
# applications, e.g. logging, status updates
|
51
|
+
#
|
52
|
+
# Parameters
|
53
|
+
# * stream +String+
|
54
|
+
#
|
55
|
+
# Returns
|
56
|
+
# @last_sequence_number +String+
|
57
|
+
#
|
58
|
+
# Notes
|
59
|
+
# This method is not implemented yet (V 0.2.7)
|
43
60
|
def flow_to_pipe(stream)
|
44
61
|
throw NotImplementedError
|
45
62
|
create_stream(stream) unless stream_exists? stream
|
@@ -53,25 +70,41 @@ module Smash
|
|
53
70
|
end
|
54
71
|
|
55
72
|
# Read messages from the Pipe without using the KCL
|
56
|
-
#
|
73
|
+
# Parameters stream String
|
74
|
+
#
|
75
|
+
# Notes
|
76
|
+
# This method is not implemented yet (V 0.2.7)
|
57
77
|
def from_pipe(stream)
|
58
78
|
# implement get_records and/or other consuming app stuff
|
59
79
|
throw NotImplementedError
|
60
80
|
end
|
61
81
|
|
82
|
+
# This message will prepare a set of collections to be sent through the Pipe
|
83
|
+
#
|
84
|
+
# Parameters
|
85
|
+
# * records
|
86
|
+
#
|
87
|
+
# Notes
|
88
|
+
# This method is not implemented yet (V 0.2.7)
|
62
89
|
def message_body_collection(records)
|
63
90
|
throw NotImplementedError
|
64
91
|
end
|
65
92
|
|
66
93
|
# Default message package. This method yields the basic configuration
|
67
94
|
# and message body for a stream and all options can be changed.
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
95
|
+
#
|
96
|
+
# Parameters opts Hash (optional)
|
97
|
+
# * stream_name: String name of the stream to pipe to
|
98
|
+
# * data: String message to send
|
99
|
+
# * partition_key: String defaults to @instance_id
|
100
|
+
#
|
101
|
+
# Returns
|
102
|
+
# +Hash+
|
103
|
+
#
|
104
|
+
# Notes:
|
105
|
+
# * See +#zfind()+
|
106
|
+
# * See +#instance_id()+
|
107
|
+
# * See +#update_message_body()+
|
75
108
|
def pipe_message_body(opts = {})
|
76
109
|
{
|
77
110
|
stream_name: zfind(opts[:stream_name]) || zfind('status_stream'),
|
@@ -82,16 +115,19 @@ module Smash
|
|
82
115
|
|
83
116
|
# Use Kinesis streams to send a message. The message is given to the method
|
84
117
|
# through a block that gets passed to the method.
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
118
|
+
#
|
119
|
+
# Parameters
|
120
|
+
# * stream +String+
|
121
|
+
# * block - a block that generates a string that will be used in the message body
|
122
|
+
#
|
123
|
+
# Returns
|
124
|
+
# the sequence_number from the sent message.
|
125
|
+
#
|
126
|
+
# Example use
|
127
|
+
# pipe_to(:status_stream) do
|
128
|
+
# # the return from the inner method is what is sent
|
129
|
+
# do_some_stuff_to_generate_a_message()
|
130
|
+
# end
|
95
131
|
def pipe_to(stream)
|
96
132
|
message = ''
|
97
133
|
create_stream(stream) unless stream_exists? stream
|
@@ -103,8 +139,11 @@ module Smash
|
|
103
139
|
end
|
104
140
|
|
105
141
|
# New stream config with sensible defaults
|
106
|
-
#
|
107
|
-
#
|
142
|
+
#
|
143
|
+
# Parameters
|
144
|
+
# * opts +Hash+ (optional)
|
145
|
+
# * * stream_name - the name to give the stream
|
146
|
+
# * * shard_count - the number of shards to create
|
108
147
|
def stream_config(opts = {})
|
109
148
|
config = {
|
110
149
|
stream_name: opts[:stream_name] || zfind(:status_stream),
|
@@ -113,8 +152,12 @@ module Smash
|
|
113
152
|
end
|
114
153
|
|
115
154
|
# Find out if the stream already exists.
|
116
|
-
#
|
117
|
-
#
|
155
|
+
#
|
156
|
+
# Parameters
|
157
|
+
# * name +String+
|
158
|
+
#
|
159
|
+
# Returns
|
160
|
+
# +Boolean+
|
118
161
|
def stream_exists?(name)
|
119
162
|
begin
|
120
163
|
kinesis.describe_stream(stream_name: name)
|
@@ -125,9 +168,12 @@ module Smash
|
|
125
168
|
end
|
126
169
|
|
127
170
|
# Get the status name for this stream
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
171
|
+
#
|
172
|
+
# Parameters
|
173
|
+
# *name +String+
|
174
|
+
#
|
175
|
+
# Returns stream status, one of:
|
176
|
+
# CREATING, DELETING, ACTIVE, UPDATING
|
131
177
|
def stream_status(name)
|
132
178
|
kinesis.describe_stream(stream_name: name).stream_description.stream_status
|
133
179
|
end
|
@@ -12,34 +12,37 @@ module Smash
|
|
12
12
|
|
13
13
|
attr_accessor :address, :name, :poller, :sqs
|
14
14
|
|
15
|
-
#
|
16
|
-
# The
|
17
|
-
#
|
15
|
+
# Creates a Board object.
|
16
|
+
# The +#new()+ method is wrapped in +#build()+ and +#create!()+ but isn't private so
|
17
|
+
# +#new()+ can be used instead of build.
|
18
18
|
# The Board doesn't create Queue(s) or any other API calls until it is instructed to.
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
19
|
+
#
|
20
|
+
# Parameters
|
21
|
+
# * name +String+ - the name of the board can be used to find its arn/url etc
|
22
|
+
#
|
23
|
+
# Returns
|
24
|
+
# +Queue::Board+
|
22
25
|
def initialize(name, this_sqs)# = sqs)
|
23
26
|
@sqs = this_sqs
|
24
27
|
@name = name
|
25
28
|
end
|
26
29
|
|
27
30
|
# Gives back a string representation of the instance variable for this board.
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
31
|
+
#
|
32
|
+
# Returns +String+ - the instance variable for this Board in string format
|
33
|
+
#
|
34
|
+
# Example
|
32
35
|
# board = Board.new(:backlog)
|
33
36
|
# Smash.instance_variable_get(board.i_var)
|
34
|
-
# #=> Board <name: :backlog ...>
|
35
|
-
# ```
|
37
|
+
# #=> Board <name: :backlog, ...>
|
36
38
|
def i_var
|
37
39
|
"@#{@name}"
|
38
40
|
end
|
39
41
|
|
40
42
|
# Gives the Queue address (URL). First the environment is searched, using Zenv and if nothing is
|
41
43
|
# found, the best guess attempt at the correct address is used.
|
42
|
-
#
|
44
|
+
#
|
45
|
+
# Returns
|
43
46
|
# * queue address <String>
|
44
47
|
def address
|
45
48
|
zfind(@name) || best_guess_address
|
@@ -49,28 +52,48 @@ module Smash
|
|
49
52
|
# to build a standard URL for SQS. The only problem with using this last resort is you may need
|
50
53
|
# to use a Queue from a different region, account or name but it can be a handy catch-all for the URLs
|
51
54
|
# for most cases.
|
52
|
-
#
|
53
|
-
#
|
55
|
+
#
|
56
|
+
# Returns String
|
57
|
+
# * exp. "https://sqs.us-west-2.amazonaws.com/12345678/fooBar"
|
54
58
|
def best_guess_address
|
55
59
|
"https://sqs.#{zfind(:aws_region)}.amazonaws.com/#{zfind(:account_number)}/#{@name}"
|
56
60
|
end
|
57
61
|
|
58
|
-
# Builds a Queue::Board object and returns it. No API calls are sent using this method
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
+
# Builds a Queue::Board object and returns it. No API calls are sent using this method. This is
|
63
|
+
# handy if you need to use a Queue but you don't want to create any resources in AWS.
|
64
|
+
#
|
65
|
+
# Parameters name +String+
|
66
|
+
#
|
67
|
+
# Returns Queue::Board
|
68
|
+
#
|
69
|
+
# Example
|
70
|
+
# exp_board = Board.build('exampleBoard')
|
71
|
+
# puts exp_board.best_guess_address
|
72
|
+
# # => 'https://sqs.us-west-2.amaz.....'
|
73
|
+
def self.build(name, this_sqs = nil)
|
62
74
|
new(name, this_sqs)
|
63
75
|
end
|
64
76
|
|
65
77
|
# Builds then Creates the Object and makes the API call to SQS to create the queue
|
66
|
-
#
|
67
|
-
#
|
68
|
-
|
78
|
+
#
|
79
|
+
# Parameters
|
80
|
+
# * name <String>
|
81
|
+
#
|
82
|
+
# Returns
|
83
|
+
# +Queue::Board+ with an actual Queue in SQS
|
84
|
+
#
|
85
|
+
# Example
|
86
|
+
# exp_board = Board.create!('exampleBoard')
|
87
|
+
# queue_search(exp_board.name)
|
88
|
+
# # => ['https://sqs.us-west-2.amazonaws.com/81234567890/exampleBoard']
|
89
|
+
def self.create!(name, this_sqs = nil)
|
69
90
|
build(name, this_sqs).create_queue!
|
70
91
|
end
|
71
92
|
|
72
|
-
# Creates an actual Queue in SQS using the standard format for
|
73
|
-
#
|
93
|
+
# Creates an actual Queue in SQS using the standard format for <b><i>this</i></b> queue name (camel case)
|
94
|
+
#
|
95
|
+
# Returns
|
96
|
+
# +Queue::Board+
|
74
97
|
def create_queue!
|
75
98
|
begin
|
76
99
|
sqs.create_queue(queue_name: to_camel(@name))
|
@@ -87,20 +110,35 @@ module Smash
|
|
87
110
|
end
|
88
111
|
|
89
112
|
# Predicate method to query SQS for the queue
|
113
|
+
#
|
114
|
+
# Example
|
115
|
+
# board = Board.build('example')
|
116
|
+
# board.exists?
|
117
|
+
# # => false
|
118
|
+
# board.save!
|
119
|
+
# board.exists?
|
120
|
+
# # => true
|
90
121
|
def exists?
|
91
122
|
queue_exists?(@name)
|
92
123
|
end
|
93
124
|
|
94
125
|
# Gets the approximate message count for a Queue using the 'ApproximateMessageCount' attribute
|
126
|
+
#
|
127
|
+
# Returns
|
128
|
+
# +Integer+
|
95
129
|
def message_count
|
96
130
|
get_queue_message_count(address)
|
97
131
|
end
|
98
132
|
|
99
|
-
# Gets a QueuePoller for the Queue attached to this Board instance
|
100
|
-
#
|
133
|
+
# Gets a QueuePoller for the Queue attached to this Board instance.
|
134
|
+
#
|
135
|
+
# Returns
|
136
|
+
# +Aws::SQS::QueuePoller+
|
137
|
+
#
|
138
|
+
# Notes
|
139
|
+
# * Provide an existing SQS Client if one exists. This is used to sort out development
|
140
|
+
# production work.
|
101
141
|
def poller
|
102
|
-
# Provide an existing SQS Client if one exists.
|
103
|
-
# This sets up stubbing and other stuff for later
|
104
142
|
args = @sqs.nil? ? address : [address, { client: sqs }]
|
105
143
|
@poller ||= Aws::SQS::QueuePoller.new(*args)
|
106
144
|
end
|
@@ -113,17 +151,25 @@ module Smash
|
|
113
151
|
# This method creates the queue in SQS for the given Board instance
|
114
152
|
# It can be coupled with the #build() method in order to use a queue without
|
115
153
|
# making the call to create it on AWS
|
154
|
+
#
|
155
|
+
# Example
|
156
|
+
# board = Board.build('example')
|
157
|
+
# board.exists?
|
158
|
+
# # => false
|
159
|
+
# board.save!
|
160
|
+
# board.exists?
|
161
|
+
# # => true
|
116
162
|
def save!
|
117
163
|
create_queue!
|
118
164
|
end
|
119
165
|
|
120
166
|
# Sends the given message to the queue
|
121
|
-
#
|
167
|
+
#
|
168
|
+
# Parameters
|
169
|
+
# * message - used as JSON or converted into it
|
122
170
|
def send_message(message)
|
123
171
|
send_queue_message(
|
124
|
-
address,
|
125
|
-
(valid_json?(message) ? message : message.to_json),
|
126
|
-
sqs
|
172
|
+
address, (valid_json?(message) ? message : message.to_json), sqs
|
127
173
|
)
|
128
174
|
end
|
129
175
|
end
|
@@ -8,12 +8,29 @@ module Smash
|
|
8
8
|
include Smash::CloudPowers::AwsResources
|
9
9
|
include Smash::CloudPowers::Helper
|
10
10
|
|
11
|
-
# A
|
11
|
+
# A simple Struct that acts as a Name to URL map
|
12
|
+
#
|
13
|
+
# Parameters
|
14
|
+
# * <tt>:set_name</tt> - name of the Queue +String+
|
15
|
+
# * <tt>:set_url</tt> - the url for the Queue +String+
|
16
|
+
#
|
17
|
+
# Example
|
18
|
+
# name_url_map = NUMap.new(nil, 'https://sqs.us-west-53.amazonaws.com/001101010010/fooBar')
|
19
|
+
# name_url_map.name
|
20
|
+
# # => 'fooBar'
|
12
21
|
NUMap = Struct.new(:set_name, :set_url) do
|
22
|
+
# Gives you back the name, even if it hasn't been set
|
23
|
+
#
|
24
|
+
# Returns
|
25
|
+
# +String+
|
13
26
|
def name
|
14
27
|
set_name || url.split('/').last # Queue names are last in the URL path
|
15
28
|
end
|
16
29
|
|
30
|
+
# Gives you back the URL, even if it hasn't been set
|
31
|
+
#
|
32
|
+
# Returns
|
33
|
+
# +String+
|
17
34
|
def url
|
18
35
|
set_url || Smash::CloudPowers::Queue::Board.new(name).best_guess_address
|
19
36
|
end
|
@@ -21,29 +38,49 @@ module Smash
|
|
21
38
|
|
22
39
|
# This method can be used to parse a queue name from its address. It can be handy if you need the name
|
23
40
|
# of a queue but you don't want the overhead of creating a Board object.
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
41
|
+
#
|
42
|
+
# Parameters
|
43
|
+
# * url +String+
|
44
|
+
#
|
45
|
+
# Returns
|
46
|
+
# +String+
|
47
|
+
#
|
48
|
+
# Example
|
49
|
+
# board_name('https://sqs.us-west-53.amazonaws.com/001101010010/fooBar')
|
50
|
+
# => fooBar
|
31
51
|
def board_name(url)
|
32
52
|
url.to_s.split('/').last
|
33
53
|
end
|
34
54
|
|
35
55
|
# This method builds a Queue::Board object for you to use but doesn't
|
36
|
-
# invoke the
|
37
|
-
# on SQS. This can be used if the
|
38
|
-
#
|
39
|
-
#
|
56
|
+
# invoke the <tt>#create!()</tt> method, so no API call is made to create the Queue
|
57
|
+
# on SQS. This can be used if the Board and/or Queue already exists.
|
58
|
+
#
|
59
|
+
# Parameters
|
60
|
+
# * name +String+ - name of the Queue you want to interact with
|
61
|
+
#
|
62
|
+
# Returns
|
63
|
+
# Queue::Board
|
64
|
+
#
|
65
|
+
# Example
|
66
|
+
# queue_object = build_queue('exampleQueue')
|
67
|
+
# queue_object.address
|
68
|
+
# => https://sqs.us-west-2.amazonaws.com/81234567/exampleQueue
|
40
69
|
def build_queue(name)
|
41
70
|
Smash::CloudPowers::Queue::Board.build(to_camel(name), sqs)
|
42
71
|
end
|
43
72
|
|
44
73
|
# This method allows you to create a queue on SQS without explicitly creating a Board object
|
45
|
-
#
|
46
|
-
#
|
74
|
+
#
|
75
|
+
# Parameters
|
76
|
+
# * name +String+ - The name of the Queue to be created
|
77
|
+
#
|
78
|
+
# Returns
|
79
|
+
# Queue::Board
|
80
|
+
#
|
81
|
+
# Example
|
82
|
+
# create_queue('exampleQueue')
|
83
|
+
# get_queue_message_count
|
47
84
|
def create_queue!(name)
|
48
85
|
begin
|
49
86
|
Smash::CloudPowers::Queue::Board.create!(to_camel(name), sqs)
|
@@ -56,9 +93,20 @@ module Smash
|
|
56
93
|
# Deletes a queue message without caring about reading/interacting with the message.
|
57
94
|
# This is usually used for progress tracking, ie; a Neuron takes a message from the Backlog, moves it to
|
58
95
|
# WIP and deletes it from Backlog. Then repeats these steps for the remaining States in the Workflow
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
96
|
+
#
|
97
|
+
# Parameters
|
98
|
+
# * queue +String+ - queue is the name of the +Queue+ to interact with
|
99
|
+
# * opts +Hash+ (optional) - a configuration +Hash+ for the +SQS::QueuePoller+
|
100
|
+
#
|
101
|
+
# Notes
|
102
|
+
# * throws :stop_polling after the message is deleted
|
103
|
+
#
|
104
|
+
# Example
|
105
|
+
# get_queue_message_count('exampleQueue')
|
106
|
+
# # => n
|
107
|
+
# delete_queue_message('exampleQueue')
|
108
|
+
# get_queue_message_count('exampleQueue')
|
109
|
+
# # => n-1
|
62
110
|
def delete_queue_message(queue, opts = {})
|
63
111
|
poll(queue, opts) do |msg, stats|
|
64
112
|
poller(queue).delete_message(msg)
|
@@ -66,9 +114,20 @@ module Smash
|
|
66
114
|
end
|
67
115
|
end
|
68
116
|
|
69
|
-
# This method is used to
|
70
|
-
#
|
71
|
-
#
|
117
|
+
# This method is used to get the approximate count of messages in a given queue
|
118
|
+
#
|
119
|
+
# Parameters
|
120
|
+
# * board_url +String+ - the URL for the board you need to get a count from
|
121
|
+
#
|
122
|
+
# Returns
|
123
|
+
# +Float+
|
124
|
+
#
|
125
|
+
# Example
|
126
|
+
# get_queue_message_count('exampleQueue')
|
127
|
+
# # => n
|
128
|
+
# delete_queue_message('exampleQueue')
|
129
|
+
# get_queue_message_count('exampleQueue')
|
130
|
+
# # => n-1
|
72
131
|
def get_queue_message_count(board_url)
|
73
132
|
sqs.get_queue_attributes(
|
74
133
|
queue_url: board_url,
|
@@ -76,8 +135,23 @@ module Smash
|
|
76
135
|
).attributes['ApproximateNumberOfMessages'].to_f
|
77
136
|
end
|
78
137
|
|
79
|
-
#
|
80
|
-
#
|
138
|
+
# Get a message from a Queue
|
139
|
+
#
|
140
|
+
# Parameters
|
141
|
+
# * board<String|symbol>: The name of the board
|
142
|
+
#
|
143
|
+
# Returns
|
144
|
+
# * +String+ if +msg.body+ is not valid JSON
|
145
|
+
# * +Hash+ if +msg.body+ is valid JSON
|
146
|
+
#
|
147
|
+
# Example
|
148
|
+
# # msg.body == 'Hey' # +String+
|
149
|
+
# pluck_queue_message('exampleQueue')
|
150
|
+
# # => 'Hey' # +String+
|
151
|
+
#
|
152
|
+
# # msg.body == "\{"tally":"ho"\}" # +JSON+
|
153
|
+
# pluck_queue_message('exampleQueue')
|
154
|
+
# # => { 'tally' => 'ho' } # +Hash+
|
81
155
|
def pluck_queue_message(board)
|
82
156
|
poll(board) do |msg, poller|
|
83
157
|
poller.delete_message(msg)
|
@@ -87,11 +161,23 @@ module Smash
|
|
87
161
|
|
88
162
|
# Polls the given board with the given options hash and a block that interacts with
|
89
163
|
# the message that is retrieved from the queue
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
164
|
+
#
|
165
|
+
# Parameters
|
166
|
+
# * +board+ +String+ - the name of the queue you want to poll
|
167
|
+
# * +opts+ +Hash+ - costomizes the Aws::SQS::QueuePoller's <tt>#poll(<b>opts</b>)</tt> method
|
168
|
+
# and can have any +AWS::SQS:QueuePoller+ polling configuration option(s)
|
169
|
+
# * +block+ is the block that is used to interact with the message that was retrieved
|
170
|
+
#
|
171
|
+
# Returns
|
172
|
+
# the results from the +message+ and the +block+ that interacts with the +message(s)+
|
173
|
+
#
|
174
|
+
# Example
|
175
|
+
# # continuously run jobs from messages in the Queue and leaves the message in the queue
|
176
|
+
# # using the +:skip_delete+ parameter
|
177
|
+
# poll(:backlog, :skip_delete) do |msg|
|
178
|
+
# demo_job = Job.new(msg.body)
|
179
|
+
# demo_job.run
|
180
|
+
# end
|
95
181
|
def poll(board_name, opts = {})
|
96
182
|
this_poller = queue_poller(board_name)
|
97
183
|
results = nil
|
@@ -106,8 +192,23 @@ module Smash
|
|
106
192
|
# This method can be used to gain a SQS::QueuePoller. It creates a Board object,
|
107
193
|
# the Board then sends the API call to SQS to create the queue and sets an instance
|
108
194
|
# variable, using the board's name, to the Board object itself
|
109
|
-
#
|
110
|
-
#
|
195
|
+
#
|
196
|
+
# Parameters
|
197
|
+
# * board_name +String+ - name of the Queue you want to gain a QueuePoller for
|
198
|
+
#
|
199
|
+
# Returns
|
200
|
+
# <tt>board_name:Queue::Board</tt>
|
201
|
+
#
|
202
|
+
# Notes
|
203
|
+
# * An instance variable is set with this method, if one doesn't exist for the board
|
204
|
+
# The instance variable that is created/used is named the same name that was given as
|
205
|
+
# a parameter.
|
206
|
+
#
|
207
|
+
# Example
|
208
|
+
# # these are equivalent after @exp_queue_poller is set but before it is set,
|
209
|
+
# # exp_queue_poller
|
210
|
+
# queue_poller('exampleQueue').poll { |msg| Job.new(msg.body).run }
|
211
|
+
# @example_queue.poll { |msg| Job.new(msg.body).run }
|
111
212
|
def queue_poller(board_name)
|
112
213
|
board = Smash::CloudPowers::Queue::Board.create!(board_name, sqs)
|
113
214
|
|
@@ -117,25 +218,50 @@ module Smash
|
|
117
218
|
instance_variable_get(board.i_var).poller
|
118
219
|
end
|
119
220
|
|
120
|
-
# Checks SQS for the existence of this queue using the
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
221
|
+
# Checks SQS for the existence of this queue using the <tt>#queue_search()</tt> method
|
222
|
+
#
|
223
|
+
# Parameters
|
224
|
+
# * name +String+
|
225
|
+
#
|
226
|
+
# Returns
|
227
|
+
# Boolean
|
228
|
+
#
|
229
|
+
# Notes:
|
230
|
+
# * see <tt>#queue_search()</tt>
|
125
231
|
def queue_exists?(name)
|
126
232
|
!queue_search(name).empty?
|
127
233
|
end
|
128
234
|
|
129
235
|
# Searches for a queue based on the name
|
130
|
-
#
|
131
|
-
#
|
236
|
+
#
|
237
|
+
# Parameters
|
238
|
+
# name +String+
|
239
|
+
#
|
240
|
+
# Returns
|
241
|
+
# queue_urls +String+
|
242
|
+
#
|
243
|
+
# Example
|
244
|
+
# results = queue_search('exampleQueue') # returns related URLs
|
245
|
+
# results.first =~ /exampleQueue/ # regex match against the URL
|
132
246
|
def queue_search(name)
|
133
247
|
sqs.list_queues(queue_name_prefix: name).queue_urls
|
134
248
|
end
|
135
249
|
|
136
250
|
# Sends a given message to a given queue
|
137
|
-
#
|
138
|
-
#
|
251
|
+
#
|
252
|
+
# Parameters
|
253
|
+
# * address +String+ - address of the Queue you want to interact with
|
254
|
+
# * message +String+ - message to be sent
|
255
|
+
#
|
256
|
+
# Returns
|
257
|
+
# <tt>Array<String></tt> - Array of URLs
|
258
|
+
#
|
259
|
+
# Example
|
260
|
+
# legit_address = 'https://sqs.us-west-2.amazonaws.com/12345678/exampleQueue'
|
261
|
+
# random_message = 'Wowza, this is pretty easy.'
|
262
|
+
# resp = send_queue_message(legit_address, random_message))
|
263
|
+
# resp.message_id
|
264
|
+
# => 'some message id'
|
139
265
|
def send_queue_message(address, message, this_sqs = sqs)
|
140
266
|
this_sqs.send_message(queue_url: address, message_body: message)
|
141
267
|
end
|
@@ -8,17 +8,18 @@ require_relative './websocket/websocclient'
|
|
8
8
|
module Smash
|
9
9
|
module CloudPowers
|
10
10
|
# The Synapse module provides all communications functionality
|
11
|
-
# - Broadcast is a module that is useful for sending 1 message to multiple recipients
|
12
|
-
# - Pipe is a module that is useful for sending large result sets, data to be processed
|
13
|
-
# or loaded, logging info and any other high-throughput/data-centric application with
|
14
|
-
# - Queue is a module that is primarily used for asynchronous communications between a sender
|
15
|
-
# and any number of users or apps that _might_ need to use it
|
16
|
-
# - WebSocServer ..._Faisal's turn_...
|
17
11
|
module Synapse
|
12
|
+
# Broadcast is a module that is useful for sending 1 message to multiple recipients
|
18
13
|
include Smash::CloudPowers::Synapse::Broadcast
|
14
|
+
# Pipe is a module that is useful for sending large result sets, data to be processed
|
15
|
+
# or loaded, logging info and any other high-throughput/data-centric application with
|
19
16
|
include Smash::CloudPowers::Synapse::Pipe
|
17
|
+
# Queue is a module that is primarily used for asynchronous communications between a sender
|
18
|
+
# and any number of users or apps that _might_ need to use it
|
20
19
|
include Smash::CloudPowers::Synapse::Queue
|
20
|
+
# WebSocClient ..._Faisal's turn_...
|
21
21
|
include Smash::CloudPowers::Synapse::WebSocClient
|
22
|
+
# WebSocServer ..._Faisal's turn_...
|
22
23
|
include Smash::CloudPowers::Synapse::WebSocServer
|
23
24
|
end
|
24
25
|
end
|
data/lib/cloud_powers/version.rb
CHANGED