active_elastic_job 1.0.0 → 1.1.0

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: d19d4e4ef144ceabffd14c20daae3b285df14616
4
- data.tar.gz: 70be0d9706ef4ae1f7a91d14380522e5263a2c31
3
+ metadata.gz: c9ced62a0162f40de919760ea5563c6bf6e6417e
4
+ data.tar.gz: 182d2fc41d98ee5fce356190e7ece9aa6d85e449
5
5
  SHA512:
6
- metadata.gz: 829d4cd3713427e6b85ed76a0a9e212b63ad5ab1232c901d30f2ad5360db90af1e242ef0fe8f37c0d01475911ad3d88e8d5dfdb22c41e17fcc3d9f04c32f5486
7
- data.tar.gz: 7cea59eaaa8091a0cfa95c103ef373874f31225223e60d87e5ce9c41b5135a9ab4db6099a66f5f6d0c384174372a838c947624e71e1a3b099b74cc905983b17d
6
+ metadata.gz: 4f7f9614d11eac062792ff694ca57a2d598f9abd882d42cdfab6fdbd538c171783a14b7f9467de56745c29c6c8688440e08c48b7cd87e19e54ca34c7a8c7b204
7
+ data.tar.gz: 9871d65f4264d52d4f13d1858093ce2e7de4929f76925f22dfb014be2a5c33370e9c1259486a645ea86bed660f0707ca60b98ac483d9bb820eccc25b943d7ef6
@@ -13,13 +13,15 @@ module ActiveElasticJob
13
13
  # environment, which verifies the digest, have to use the *same*
14
14
  # +secrets.secret_key_base+ setting.
15
15
  class SqsMessageConsumer
16
+ USER_AGENT_PREFIX = 'aws-sqsd'
17
+
16
18
  def initialize(app) #:nodoc:
17
19
  @app = app
18
20
  end
19
21
 
20
22
  def call(env) #:nodoc:
21
23
  request = ActionDispatch::Request.new env
22
- if request.headers['User-Agent'] =~ /aws-sqsd/
24
+ if aws_sqsd?(request)
23
25
  begin
24
26
  verify(request)
25
27
  job = JSON.load(request.body)
@@ -38,9 +40,21 @@ module ActiveElasticJob
38
40
 
39
41
  def verify(request)
40
42
  secret_key_base = Rails.application.secrets[:secret_key_base]
41
- verifier = ActiveElasticJob::MessageVerifier.new(secret_key_base)
43
+ @verifier ||= ActiveElasticJob::MessageVerifier.new(secret_key_base)
42
44
  digest = request.headers['HTTP_X_AWS_SQSD_ATTR_MESSAGE_DIGEST']
43
- verifier.verify(request.body.string, digest)
45
+ @verifier.verify(request.body.string, digest)
46
+ end
47
+
48
+ def aws_sqsd?(request)
49
+ # we do not match against a Regexp
50
+ # in order to avoid performance penalties.
51
+ # Instead we make a simple string comparison.
52
+ # Benchmark runs showed an performance increase of
53
+ # up to 40%
54
+ current_user_agent = request.headers['User-Agent']
55
+ return (current_user_agent.present? &&
56
+ current_user_agent.size >= USER_AGENT_PREFIX.size &&
57
+ current_user_agent[0..(USER_AGENT_PREFIX.size - 1)] == USER_AGENT_PREFIX)
44
58
  end
45
59
  end
46
60
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveElasticJob
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -29,7 +29,7 @@ module ActiveJob
29
29
  See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
30
30
  for further details!
31
31
  MSG
32
- raise RangeError, 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
32
+ raise RangeError, msg if delay > 15.minutes
33
33
  end
34
34
 
35
35
  aws_sqs_client.send_message(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_elastic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tawan Sierek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-03 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler