mturk 1.8.1 → 1.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2824ace506e32d3d0b6cba0806e4472e0c8a374f
4
- data.tar.gz: 77f5276b908ee6eea5ab1557012a40bd0b054aee
3
+ metadata.gz: b055d3df233877b411415ee5bc49333d4e5e631b
4
+ data.tar.gz: 07e95e1534f167c8b25f71f91e1000d668de60ca
5
5
  SHA512:
6
- metadata.gz: 9b8ed5e600b26db8465470a385ea4b09873c7c9aaa91fc8643347cddbac6c560b1b0a132dc240a4aaead75d35c463b35d179db59a73b37c441b47f6d6a39dad6
7
- data.tar.gz: 43c7b5bf39c6a8e07037a3affd2cc75317cf6da84c1b175baa0d63aa3211ad5982532f4784ff0f6dc699fc5df6ccf29de24c8d4f0f54ed5c28c2fb3324276701
6
+ metadata.gz: 131b073c825340bfc2d96a01eb45eda4ced2b190ba6a119ca2019a6b0fe9effecb8179d880d5be018a8ce7460a480963a653e11e2520f97b531b0c83768c62fd
7
+ data.tar.gz: d38d47fe0cbbe11a13eca73896ab1177eb4998ae5b91a825d88940a37ad25d63149a3ac2d46fd739ab92f38038af43551272ac1c20fa1c1c8ce086570138a171
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.md CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.9.0 / 2015-09-14
2
+
3
+ === 1 major enhancement
4
+ * Safely retry CreateHIT, ExtendHIT, and GrantBonus operations
5
+
1
6
  == 1.8.1 / 2015-02-16
2
7
 
3
8
  === 1 minor update
@@ -47,10 +47,12 @@ class MechanicalTurkRequester < Amazon::WebServices::Util::ConvenienceWrapper
47
47
  :AutoApprovalDelayInSeconds => 60*60*24*7,
48
48
  :LifetimeInSeconds => 60*60*24,
49
49
  }
50
+ idempotent :CreateHIT
50
51
 
51
52
  serviceCall :DisableHIT, :DisableHITResult
52
53
  serviceCall :DisposeHIT, :DisposeHITResult
53
54
  serviceCall :ExtendHIT, :ExtendHITResult
55
+ idempotent :ExtendHIT
54
56
  serviceCall :ForceExpireHIT, :ForceExpireHITResult
55
57
  serviceCall :GetHIT, :HIT, { :ResponseGroup => %w( Minimal HITDetail HITQuestion HITAssignmentSummary ) }
56
58
  serviceCall :ChangeHITTypeOfHIT, :ChangeHITTypeOfHITResult
@@ -71,6 +73,7 @@ class MechanicalTurkRequester < Amazon::WebServices::Util::ConvenienceWrapper
71
73
  serviceCall :ApproveRejectedAssignment, :ApproveRejectedAssignmentResult
72
74
 
73
75
  serviceCall :GrantBonus, :GrantBonusResult
76
+ idempotent :GrantBonus
74
77
  serviceCall :GetBonusPayments, :GetBonusPaymentsResult
75
78
 
76
79
  serviceCall :CreateQualificationType, :QualificationType, { :QualificationTypeStatus => 'Active' }
@@ -51,6 +51,29 @@ class ConvenienceWrapper
51
51
  end
52
52
  end
53
53
 
54
+ DEFAULT_UNIQUE_REQUEST_TOKEN_FACTORY = proc do |params|
55
+ time_hash = Time.now.hash.to_s(36)
56
+ rand_hash = rand(1679615).to_s(36)
57
+ params_hash = params.hash.to_s(36)
58
+ "#{params_hash}#{time_hash}#{rand_hash}"
59
+ end
60
+
61
+ def self.idempotent( method, key=:UniqueRequestToken, factory = DEFAULT_UNIQUE_REQUEST_TOKEN_FACTORY )
62
+ method = method.to_s
63
+ method = ( method[0..0].downcase + method[1..-1] ).to_sym
64
+ old_method = instance_method(method)
65
+
66
+ define_method(method) do |*params|
67
+ userArgs = params[0] || {}
68
+ args = if userArgs.has_key?(key)
69
+ userArgs
70
+ else
71
+ { key => factory.call(userArgs) }.merge(userArgs)
72
+ end
73
+ old_method.bind(self).(args)
74
+ end
75
+ end
76
+
54
77
  def self.paginate( method, elementTag, pageSize=25 )
55
78
  method = method.to_s
56
79
  all_name = ( method[0..0].downcase + method[1..-1] + "All" ).to_sym
data/lib/mturk/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # License:: Apache License, Version 2.0
3
3
 
4
4
  module MTurk
5
- VERSION = '1.8.1'.freeze
5
+ VERSION = '1.9.0'.freeze
6
6
  end
@@ -47,9 +47,9 @@ class TestErrorHandler < Test::Unit::TestCase
47
47
  nil
48
48
  end
49
49
 
50
- # invoking a non-retryable call will throw an exception
50
+ # invoking a non-retryable call will throw an exception if we explicitly skip passing in :UniqueRequestToken
51
51
  begin
52
- @mturk.grantBonus
52
+ @mturk.grantBonus UniqueRequestToken: nil
53
53
  fail "Should have thrown an exception"
54
54
  rescue Timeout::Error
55
55
  # expect this exception
@@ -77,6 +77,25 @@ class TestErrorHandler < Test::Unit::TestCase
77
77
  @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
78
78
  end
79
79
 
80
+ def testTimeoutOnceRetryableDefaultUniqueRequestToken
81
+ # mock will timeout first time, return success on second call
82
+ should_fail = true
83
+ @mock.listen do |call|
84
+ Timeout.timeout(1) do
85
+ if should_fail
86
+ should_fail = false
87
+ sleep(2)
88
+ end
89
+ end
90
+ nil
91
+ end
92
+
93
+ # invoke call, library will automatically insert a unique idempotency token
94
+ @mturk.grantBonus
95
+ assert_equal 2, @mock.call_buffer.size, "Should have retried once"
96
+ @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
97
+ end
98
+
80
99
  def testTimeoutAlways
81
100
  #mock will always timeout
82
101
  @mock.listen do |call|
@@ -126,7 +145,7 @@ class TestErrorHandler < Test::Unit::TestCase
126
145
 
127
146
  # invoking a non-retryable call will throw an exception
128
147
  begin
129
- @mturk.grantBonus
148
+ @mturk.grantBonus UniqueRequestToken: nil
130
149
  fail "Should have thrown an exception"
131
150
  rescue Errno::ECONNRESET
132
151
  # expect this exception
@@ -152,6 +171,23 @@ class TestErrorHandler < Test::Unit::TestCase
152
171
  @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
153
172
  end
154
173
 
174
+ def testResetConnectionOnceDefaultRetryableUniqueRequestToken
175
+ # mock will reset connection first time, return success on second call
176
+ should_fail = true
177
+ @mock.listen do |call|
178
+ if should_fail
179
+ should_fail = false
180
+ raise Errno::ECONNRESET
181
+ end
182
+ nil
183
+ end
184
+
185
+ # invoke call, library will automatically insert a unique idempotency token
186
+ @mturk.grantBonus
187
+ assert_equal 2, @mock.call_buffer.size, "Should have retried once"
188
+ @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
189
+ end
190
+
155
191
  def testResetConnectionAlways
156
192
  #mock will always reset connection
157
193
  @mock.listen do |call|
@@ -201,7 +237,7 @@ class TestErrorHandler < Test::Unit::TestCase
201
237
 
202
238
  # invoking a non-retryable call will throw an exception
203
239
  begin
204
- @mturk.grantBonus
240
+ @mturk.grantBonus UniqueRequestToken: nil
205
241
  fail "Should have thrown an exception"
206
242
  rescue Errno::EPIPE
207
243
  # expect this exception
@@ -227,6 +263,23 @@ class TestErrorHandler < Test::Unit::TestCase
227
263
  @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
228
264
  end
229
265
 
266
+ def testPipeBrokenOnceRetryableDefaultUniqueRequestToken
267
+ # mock will reset connection first time, return success on second call
268
+ should_fail = true
269
+ @mock.listen do |call|
270
+ if should_fail
271
+ should_fail = false
272
+ raise Errno::EPIPE
273
+ end
274
+ nil
275
+ end
276
+
277
+ # invoke call, library will automatically insert a unique idempotency token
278
+ @mturk.grantBonus
279
+ assert_equal 2, @mock.call_buffer.size, "Should have retried once"
280
+ @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
281
+ end
282
+
230
283
  def testPipeBrokenAlways
231
284
  #mock will always break pipe
232
285
  @mock.listen do |call|
@@ -276,7 +329,7 @@ class TestErrorHandler < Test::Unit::TestCase
276
329
 
277
330
  # invoking a non-retryable call will throw an exception
278
331
  begin
279
- @mturk.grantBonus
332
+ @mturk.grantBonus UniqueRequestToken: nil
280
333
  fail "Should have thrown an exception"
281
334
  rescue Amazon::WebServices::Util::ValidationException
282
335
  # expect this exception
@@ -302,6 +355,23 @@ class TestErrorHandler < Test::Unit::TestCase
302
355
  @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
303
356
  end
304
357
 
358
+ def testServiceUnavailableOnceRetryableDefaultUniqueRequestToken
359
+ # mock will reset connection first time, return success on second call
360
+ should_fail = true
361
+ @mock.listen do |call|
362
+ if should_fail
363
+ should_fail = false
364
+ raise Amazon::WebServices::Util::ValidationException.new(nil, 'AWS.ServiceUnavailable')
365
+ end
366
+ nil
367
+ end
368
+
369
+ # invoke call, library will automatically insert a unique idempotency token
370
+ @mturk.grantBonus
371
+ assert_equal 2, @mock.call_buffer.size, "Should have retried once"
372
+ @mock.each {|call| assert_equal :GrantBonus, call.name, "Should have been a GrantBonus call" }
373
+ end
374
+
305
375
  def testServiceUnavailableAlways
306
376
  #mock will always break pipe
307
377
  @mock.listen do |call|
@@ -39,7 +39,7 @@ class TestMockMechanicalTurkRequester < Test::Unit::TestCase
39
39
  default_call = @mock.next # request from convenience layer
40
40
  request = default_call.request
41
41
  assert !request.keys.empty?
42
- expected = [:MaxAssignments, :AssignmentDurationInSeconds, :AutoApprovalDelayInSeconds, :LifetimeInSeconds]
42
+ expected = [:MaxAssignments, :AssignmentDurationInSeconds, :AutoApprovalDelayInSeconds, :LifetimeInSeconds, :UniqueRequestToken]
43
43
  assert_equal [], request.keys - expected, 'Convenience layer should not populate unexpected arguments'
44
44
  assert_equal [], expected - request.keys, 'Convenience layer should populate all expected arguments'
45
45
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mturk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David J Parrott
@@ -29,7 +29,7 @@ cert_chain:
29
29
  tlC13CXjOWGW+hn+n/swny4LFXOus/qZixxiMAePSmN3QUC+bl/GvdBqZz0uPmQc
30
30
  QRVpdW2BFol3aw2mXmdYxaOwHvTxcB7DHmkfOf2h
31
31
  -----END CERTIFICATE-----
32
- date: 2015-02-17 00:00:00.000000000 Z
32
+ date: 2015-09-14 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: highline
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  requirements: []
204
204
  rubyforge_project:
205
- rubygems_version: 2.4.5
205
+ rubygems_version: 2.4.8
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: Ruby libraries for working with Mechanical Turk
metadata.gz.sig CHANGED
Binary file