cloud_powers 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 403667ef1b83f93c4534a4273849b4cd471385e4
4
- data.tar.gz: c233cc41bd999aaa9b0bc6cc58d1a08c1947af73
3
+ metadata.gz: 9cc966e1561d2a202cfa35dd2cf3147d4ef2b840
4
+ data.tar.gz: d371b86048fef80382f4bc6cd61a3a4a5a7d16bf
5
5
  SHA512:
6
- metadata.gz: bcad8e1544017abf5b498b546271cadb8071d1c498fd599983e9d4e5d7ed391d3033e82589ddd0aec49a171cb098804dfad9d0439d19cb5fb7f10a23d80d3828
7
- data.tar.gz: a95f21bad47ff61cf1175716dff63322dc20908b25d92201a59fb61d785f86121e9589b5c4ee939fa0fef02a64ad633fd247c8a0a490f7f2ba26732d27010bab
6
+ metadata.gz: 2125004e0684f341d86a5c04ad62edeafb44ee8de978a7487518d319594e0ac165296170cdb1930a6e1928814198c9dd67729a9d0ba8cb10d8604a072b94c78a
7
+ data.tar.gz: 8fc1f114aa0be9caedd619e611d3e3014ac31c3f55113b0ba661a50f1b014e3996c711c8a108601673044c0b4aca22307b2f308fae73679119a724de192c2b0d
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.4.0
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cloud_powers/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.required_ruby_version = '~> 2.3.0'
7
+ spec.required_ruby_version = '~> 2.4.0'
8
8
  spec.name = 'cloud_powers'
9
9
  spec.version = CloudPowers::VERSION
10
10
  spec.authors = ['Adam Phillipps', 'Faisal Irfan', 'Gerardo Parajeles']
@@ -45,8 +45,8 @@ Gem::Specification.new do |spec|
45
45
  spec.add_runtime_dependency 'websocket-eventmachine-client'
46
46
  spec.add_runtime_dependency 'workflow'
47
47
 
48
- spec.add_development_dependency 'bundler', '~> 1.13.5'
48
+ spec.add_development_dependency 'bundler', '~> 1.14.3'
49
49
  spec.add_development_dependency 'byebug', '~> 9'
50
- spec.add_development_dependency 'rake', '~> 10.0'
51
- spec.add_development_dependency 'rspec', '~> 3.0'
50
+ spec.add_development_dependency 'rake', '~> 12.0'
51
+ spec.add_development_dependency 'rspec', '~> 3.5'
52
52
  end
@@ -1,3 +1,3 @@
1
1
  module CloudPowers
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_powers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Phillipps
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2016-12-23 00:00:00.000000000 Z
13
+ date: 2017-02-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport-core-ext
@@ -144,14 +144,14 @@ dependencies:
144
144
  requirements:
145
145
  - - "~>"
146
146
  - !ruby/object:Gem::Version
147
- version: 1.13.5
147
+ version: 1.14.3
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - "~>"
153
153
  - !ruby/object:Gem::Version
154
- version: 1.13.5
154
+ version: 1.14.3
155
155
  - !ruby/object:Gem::Dependency
156
156
  name: byebug
157
157
  requirement: !ruby/object:Gem::Requirement
@@ -172,28 +172,28 @@ dependencies:
172
172
  requirements:
173
173
  - - "~>"
174
174
  - !ruby/object:Gem::Version
175
- version: '10.0'
175
+ version: '12.0'
176
176
  type: :development
177
177
  prerelease: false
178
178
  version_requirements: !ruby/object:Gem::Requirement
179
179
  requirements:
180
180
  - - "~>"
181
181
  - !ruby/object:Gem::Version
182
- version: '10.0'
182
+ version: '12.0'
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: rspec
185
185
  requirement: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - "~>"
188
188
  - !ruby/object:Gem::Version
189
- version: '3.0'
189
+ version: '3.5'
190
190
  type: :development
191
191
  prerelease: false
192
192
  version_requirements: !ruby/object:Gem::Requirement
193
193
  requirements:
194
194
  - - "~>"
195
195
  - !ruby/object:Gem::Version
196
- version: '3.0'
196
+ version: '3.5'
197
197
  description: |2
198
198
  CloudPowers is a wrapper around AWS and in the future, other cloud service Providers.
199
199
  It was developed specifically for the Brain project but hopefully can be used
@@ -256,7 +256,6 @@ files:
256
256
  - lib/cloud_powers/synapse/queue.rb
257
257
  - lib/cloud_powers/synapse/queue/board.rb
258
258
  - lib/cloud_powers/synapse/queue/poller.rb
259
- - lib/cloud_powers/synapse/queue/queue.rb
260
259
  - lib/cloud_powers/synapse/synapse.rb
261
260
  - lib/cloud_powers/synapse/web_soc.rb
262
261
  - lib/cloud_powers/synapse/web_soc/soc_client.rb
@@ -275,7 +274,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
274
  requirements:
276
275
  - - "~>"
277
276
  - !ruby/object:Gem::Version
278
- version: 2.3.0
277
+ version: 2.4.0
279
278
  required_rubygems_version: !ruby/object:Gem::Requirement
280
279
  requirements:
281
280
  - - ">="
@@ -283,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
282
  version: '0'
284
283
  requirements: []
285
284
  rubyforge_project:
286
- rubygems_version: 2.5.1
285
+ rubygems_version: 2.6.8
287
286
  signing_key:
288
287
  specification_version: 4
289
288
  summary: Cloud providers wrapper. Currently only AWS is supported.
@@ -1,282 +0,0 @@
1
- require 'uri'
2
- require_relative 'board'
3
-
4
- module Smash
5
- module CloudPowers
6
- module Synapse
7
- module Queue
8
- include Smash::CloudPowers::AwsResources
9
- include Smash::CloudPowers::Helper
10
-
11
- # A simple Struct that acts as a Name to URL map
12
- #
13
- # Parameters
14
- # * :set_name +String+ (optional) - An optional name. It should be the same name as the
15
- # the Board and/or Queue you're working with, or else this Struct isn't that useful
16
- # * :set_url +String+ (optional) - An optional URL. It should be the same URL as the
17
- # the Board and/or Queue you're working with, or else this Struct isn't that useful
18
- #
19
- # Attributes
20
- # * name +String+ - the +:set_name+ or parse the +#address()+ for the name
21
- # * url +String+ - the +:set_url+ or add the name to the end of a best guess at the URL
22
- #
23
- # Example
24
- # name_url_map = NUMap.new(nil, 'https://sqs.us-west-53.amazonaws.com/001101010010/fooBar')
25
- # name_url_map.name
26
- # # => 'fooBar'
27
- #
28
- # # and now in reverse
29
- # url_name_map = NUMap.new('snargleBargle')
30
- # url_name_map.address
31
- # # => 'https://sqs.us-west-53.amazonaws.com/001101010010/snargleBargle'
32
- NUMap = Struct.new(:set_name, :set_url) do
33
- # Gives you back the name, even if it hasn't been set
34
- #
35
- # Returns
36
- # +String+
37
- def name
38
- set_name || url.split('/').last # Queue names are last in the URL path
39
- end
40
-
41
- # Gives you back the URL, even if it hasn't been set
42
- #
43
- # Returns
44
- # +String+
45
- def url
46
- set_url || Smash::CloudPowers::Queue::Board.new(name).best_guess_address
47
- end
48
- end
49
-
50
- # This method can be used to parse a queue name from its address. It can be handy if you need the name
51
- # of a queue but you don't want the overhead of creating a Board object.
52
- #
53
- # Parameters
54
- # * url +String+
55
- #
56
- # Returns
57
- # +String+
58
- #
59
- # Example
60
- # board_name('https://sqs.us-west-53.amazonaws.com/001101010010/fooBar')
61
- # => fooBar
62
- def board_name(url)
63
- url.to_s.split('/').last
64
- end
65
-
66
- # This method builds a Queue::Board object for you to use but doesn't
67
- # invoke the <tt>#create!()</tt> method, so no API call is made to create the Queue
68
- # on SQS. This can be used if the Board and/or Queue already exists.
69
- #
70
- # Parameters
71
- # * name +String+ - name of the Queue you want to interact with
72
- #
73
- # Returns
74
- # Queue::Board
75
- #
76
- # Example
77
- # queue_object = build_queue('exampleQueue')
78
- # queue_object.address
79
- # => https://sqs.us-west-2.amazonaws.com/81234567/exampleQueue
80
- def build_queue(name)
81
- Smash::CloudPowers::Queue::Board.build(to_camel(name), sqs)
82
- end
83
-
84
- # This method allows you to create a queue on SQS without explicitly creating a Board object
85
- #
86
- # Parameters
87
- # * name +String+ - The name of the Queue to be created
88
- #
89
- # Returns
90
- # Queue::Board
91
- #
92
- # Example
93
- # create_queue('exampleQueue')
94
- # get_queue_message_count
95
- def create_queue!(name)
96
- begin
97
- Smash::CloudPowers::Queue::Board.create!(to_camel(name), sqs)
98
- rescue Aws::SQS::Errors::QueueDeletedRecently
99
- sleep 5
100
- retry
101
- end
102
- end
103
-
104
- # Deletes a queue message without caring about reading/interacting with the message.
105
- # This is usually used for progress tracking, ie; a Neuron takes a message from the Backlog, moves it to
106
- # WIP and deletes it from Backlog. Then repeats these steps for the remaining States in the Workflow
107
- #
108
- # Parameters
109
- # * queue +String+ - queue is the name of the +Queue+ to interact with
110
- # * opts +Hash+ (optional) - a configuration +Hash+ for the +SQS::QueuePoller+
111
- #
112
- # Notes
113
- # * throws :stop_polling after the message is deleted
114
- #
115
- # Example
116
- # get_queue_message_count('exampleQueue')
117
- # # => n
118
- # delete_queue_message('exampleQueue')
119
- # get_queue_message_count('exampleQueue')
120
- # # => n-1
121
- def delete_queue_message(queue, opts = {})
122
- poll(queue, opts) do |msg, stats|
123
- poller(queue).delete_message(msg)
124
- throw :stop_polling
125
- end
126
- end
127
-
128
- # This method is used to get the approximate count of messages in a given queue
129
- #
130
- # Parameters
131
- # * board_url +String+ - the URL for the board you need to get a count from
132
- #
133
- # Returns
134
- # +Float+
135
- #
136
- # Example
137
- # get_queue_message_count('exampleQueue')
138
- # # => n
139
- # delete_queue_message('exampleQueue')
140
- # get_queue_message_count('exampleQueue')
141
- # # => n-1
142
- def get_queue_message_count(board_url)
143
- sqs.get_queue_attributes(
144
- queue_url: board_url,
145
- attribute_names: ['ApproximateNumberOfMessages']
146
- ).attributes['ApproximateNumberOfMessages'].to_f
147
- end
148
-
149
- # Get a message from a Queue
150
- #
151
- # Parameters
152
- # * board<String|symbol>: The name of the board
153
- #
154
- # Returns
155
- # * +String+ if +msg.body+ is not valid JSON
156
- # * +Hash+ if +msg.body+ is valid JSON
157
- #
158
- # Example
159
- # # msg.body == 'Hey' # +String+
160
- # pluck_queue_message('exampleQueue')
161
- # # => 'Hey' # +String+
162
- #
163
- # # msg.body == "\{"tally":"ho"\}" # +JSON+
164
- # pluck_queue_message('exampleQueue')
165
- # # => { 'tally' => 'ho' } # +Hash+
166
- def pluck_queue_message(board)
167
- poll(board) do |msg, poller|
168
- poller.delete_message(msg)
169
- return valid_json?(msg.body) ? JSON.parse(msg.body) : msg.body
170
- end
171
- end
172
-
173
- # Polls the given board with the given options hash and a block that interacts with
174
- # the message that is retrieved from the queue
175
- #
176
- # Parameters
177
- # * +board+ +String+ - the name of the queue you want to poll
178
- # * +opts+ +Hash+ - costomizes the Aws::SQS::QueuePoller's <tt>#poll(<b>opts</b>)</tt> method
179
- # and can have any +AWS::SQS:QueuePoller+ polling configuration option(s)
180
- # * +block+ is the block that is used to interact with the message that was retrieved
181
- #
182
- # Returns
183
- # the results from the +message+ and the +block+ that interacts with the +message(s)+
184
- #
185
- # Example
186
- # # continuously run jobs from messages in the Queue and leaves the message in the queue
187
- # # using the +:skip_delete+ parameter
188
- # poll(:backlog, :skip_delete) do |msg|
189
- # demo_job = Job.new(msg.body)
190
- # demo_job.run
191
- # end
192
- def poll(board_name, opts = {})
193
- this_poller = queue_poller(board_name)
194
- results = nil
195
- this_poller.poll(opts) do |msg|
196
- results = yield msg, this_poller if block_given?
197
- this_poller.delete_message(msg)
198
- throw :stop_polling
199
- end
200
- results
201
- end
202
-
203
- # This method can be used to gain a SQS::QueuePoller. It creates a Board object,
204
- # the Board then sends the API call to SQS to create the queue and sets an instance
205
- # variable, using the board's name, to the Board object itself
206
- #
207
- # Parameters
208
- # * board_name +String+ - name of the Queue you want to gain a QueuePoller for
209
- #
210
- # Returns
211
- # <tt>board_name:Queue::Board</tt>
212
- #
213
- # Notes
214
- # * An instance variable is set with this method, if one doesn't exist for the board
215
- # The instance variable that is created/used is named the same name that was given as
216
- # a parameter.
217
- #
218
- # Example
219
- # # these are equivalent after @exp_queue_poller is set but before it is set,
220
- # # exp_queue_poller
221
- # queue_poller('exampleQueue').poll { |msg| Job.new(msg.body).run }
222
- # @example_queue.poll { |msg| Job.new(msg.body).run }
223
- def queue_poller(board_name)
224
- board = Smash::CloudPowers::Queue::Board.create!(board_name, sqs)
225
-
226
- unless instance_variable_defined?(board.i_var)
227
- instance_variable_set(board.i_var, board)
228
- end
229
- instance_variable_get(board.i_var).poller
230
- end
231
-
232
- # Checks SQS for the existence of this queue using the <tt>#queue_search()</tt> method
233
- #
234
- # Parameters
235
- # * name +String+
236
- #
237
- # Returns
238
- # Boolean
239
- #
240
- # Notes
241
- # * see <tt>#queue_search()</tt>
242
- def queue_exists?(name)
243
- !queue_search(name).empty?
244
- end
245
-
246
- # Searches for a queue based on the name
247
- #
248
- # Parameters
249
- # name +String+
250
- #
251
- # Returns
252
- # queue_urls +String+
253
- #
254
- # Example
255
- # results = queue_search('exampleQueue') # returns related URLs
256
- # results.first =~ /exampleQueue/ # regex match against the URL
257
- def queue_search(name)
258
- sqs.list_queues(queue_name_prefix: name).queue_urls
259
- end
260
-
261
- # Sends a given message to a given queue
262
- #
263
- # Parameters
264
- # * address +String+ - address of the Queue you want to interact with
265
- # * message +String+ - message to be sent
266
- #
267
- # Returns
268
- # <tt>Array<String></tt> - Array of URLs
269
- #
270
- # Example
271
- # legit_address = 'https://sqs.us-west-2.amazonaws.com/12345678/exampleQueue'
272
- # random_message = 'Wowza, this is pretty easy.'
273
- # resp = send_queue_message(legit_address, random_message))
274
- # resp.message_id
275
- # => 'some message id'
276
- def send_queue_message(address, message, this_sqs = sqs)
277
- this_sqs.send_message(queue_url: address, message_body: message)
278
- end
279
- end
280
- end
281
- end
282
- end