active_elastic_job 3.0.0 → 3.1.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
  SHA256:
3
- metadata.gz: 4fa6153074f7ae6a834972d070137734873cafdf2fe4807ead1a838ca9d497cf
4
- data.tar.gz: e1b5905ce2c23f3d11a795883e8ee7be8be9c60fd391af4c76a2c252b99c6a4a
3
+ metadata.gz: 7314269003451ee2d9b211948b70a351621f340395ffddcf47e7f8362a5e4d4e
4
+ data.tar.gz: 3b75e291c60225b28aaf879143e49ba16955bd3faed096a9b1c7dc6804aa40f8
5
5
  SHA512:
6
- metadata.gz: 32dfb859495c2658137eb010c4e58e8be5872e8be54a6e245852157beefb2ce1bf542a350d263b9b493d70ce0a4d5f26d935a14e325f6eabd9c6f75bb2ce5d24
7
- data.tar.gz: 2a44d66bef9a7903abb96c2d2ca899465cf8cd34ea770eb96cab20ccccffa4ee60360cbca2f7ceba0f9ff31709cc890d37fc219de11beda451df1f9e49016ffe
6
+ metadata.gz: 0fe756ae355407bb1f923850efbb53e6587dcb136aee42b64467780ab73bc1935210494039a88e02ea7d525846bdcd90ac398136ca33c6389dae66be975d417b
7
+ data.tar.gz: c6cb04a7f3acee2cce0991d66b665ed544d42903f9b89a124705717af8b3787fd6b4e69de60d0d1c78ff03bde436377d803fc169f3accff0d6f61f50297e1e98
@@ -25,7 +25,10 @@ module ActiveElasticJob
25
25
  { 'Content-Type'.freeze => 'text/plain'.freeze },
26
26
  [ 'Request forbidden!'.freeze ]
27
27
  ]
28
- DOCKER_HOST_IP = /172.17.0.\d+/.freeze
28
+
29
+ # 172.17.0.x is the default for Docker
30
+ # 172.18.0.x is the default for the bridge network of Docker Compose
31
+ DOCKER_HOST_IP = /172.1(7|8).0.\d+/.freeze
29
32
 
30
33
  def initialize(app) #:nodoc:
31
34
  @app = app
@@ -33,7 +36,7 @@ module ActiveElasticJob
33
36
 
34
37
  def call(env) #:nodoc:
35
38
  request = ActionDispatch::Request.new env
36
- if enabled? && aws_sqsd?(request)
39
+ if enabled? && (aws_sqsd?(request) || sqsd?(request))
37
40
  unless request.local? || sent_from_docker_host?(request)
38
41
  return FORBIDDEN_RESPONSE
39
42
  end
@@ -87,6 +90,18 @@ module ActiveElasticJob
87
90
  current_user_agent[0..('aws-sqsd'.freeze.size - 1)] == 'aws-sqsd'.freeze)
88
91
  end
89
92
 
93
+ def sqsd?(request)
94
+ # Does not match against a Regexp
95
+ # in order to avoid performance penalties.
96
+ # Instead performs a simple string comparison.
97
+ # Benchmark runs showed an performance increase of
98
+ # up to 40%
99
+ current_user_agent = request.headers['User-Agent'.freeze]
100
+ return (current_user_agent.present? &&
101
+ current_user_agent.size >= 'sqsd'.freeze.size &&
102
+ current_user_agent[0..('sqsd'.freeze.size - 1)] == 'sqsd'.freeze)
103
+ end
104
+
90
105
  def periodic_tasks_route
91
106
  @periodic_tasks_route ||= config.periodic_tasks_route
92
107
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveElasticJob
2
2
  module VERSION
3
3
  MAJOR = 3
4
- MINOR = 0
4
+ MINOR = 1
5
5
  TINY = 0
6
6
  PRE = nil
7
7
 
@@ -130,23 +130,42 @@ module ActiveJob
130
130
  end
131
131
 
132
132
  def build_message(queue_name, serialized_job, timestamp)
133
- {
133
+ args = {
134
134
  queue_url: queue_url(queue_name),
135
135
  message_body: serialized_job,
136
136
  delay_seconds: calculate_delay(timestamp),
137
- message_attributes: {
138
- "message-digest".freeze => {
139
- string_value: message_digest(serialized_job),
140
- data_type: "String".freeze
141
- },
142
- origin: {
143
- string_value: ActiveElasticJob::ACRONYM,
144
- data_type: "String".freeze
145
- }
137
+ message_attributes: build_message_attributes(serialized_job)
138
+ }
139
+
140
+ if queue_name.split('.').last == 'fifo'
141
+ args.merge!(fifo_required_params(serialized_job))
142
+ end
143
+
144
+ return args
145
+ end
146
+
147
+ def build_message_attributes(serialized_job)
148
+ {
149
+ "message-digest".freeze => {
150
+ string_value: message_digest(serialized_job),
151
+ data_type: "String".freeze
152
+ },
153
+ origin: {
154
+ string_value: ActiveElasticJob::ACRONYM,
155
+ data_type: "String".freeze
146
156
  }
147
157
  }
148
158
  end
149
159
 
160
+ def fifo_required_params(serialized_job)
161
+ parsed_job = JSON.parse(serialized_job)
162
+
163
+ {
164
+ message_group_id: parsed_job['job_class'],
165
+ message_deduplication_id: parsed_job['job_id']
166
+ }
167
+ end
168
+
150
169
  def queue_url(queue_name)
151
170
  cache_key = queue_name.to_s
152
171
  @queue_urls ||= { }
@@ -198,13 +217,13 @@ module ActiveJob
198
217
  Rails.application.config.active_elastic_job
199
218
  end
200
219
 
201
- def message_digest(messsage_body)
220
+ def message_digest(message_body)
202
221
  @verifier ||= ActiveElasticJob::MessageVerifier.new(secret_key_base)
203
- @verifier.generate_digest(messsage_body)
222
+ @verifier.generate_digest(message_body)
204
223
  end
205
224
 
206
- def verify_md5_digests!(response, messsage_body, message_attributes)
207
- calculated = md5_of_message_body(messsage_body)
225
+ def verify_md5_digests!(response, message_body, message_attributes)
226
+ calculated = md5_of_message_body(message_body)
208
227
  returned = response.md5_of_message_body
209
228
  if calculated != returned
210
229
  raise MD5MismatchError.new response.message_id, calculated, returned
@@ -213,7 +232,7 @@ module ActiveJob
213
232
  if message_attributes
214
233
  calculated = md5_of_message_attributes(message_attributes)
215
234
  returned = response.md5_of_message_attributes
216
- if calculated != returned
235
+ if calculated != returned
217
236
  raise MD5MismatchError.new response.message_id, calculated, returned
218
237
  end
219
238
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_elastic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tawan Sierek
8
8
  - Joey Paris
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-22 00:00:00.000000000 Z
12
+ date: 2021-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-sqs
@@ -207,7 +207,7 @@ homepage: https://github.com/active-elastic-job/active-elastic-job
207
207
  licenses:
208
208
  - MIT
209
209
  metadata: {}
210
- post_install_message:
210
+ post_install_message:
211
211
  rdoc_options: []
212
212
  require_paths:
213
213
  - lib
@@ -222,8 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubygems_version: 3.1.2
226
- signing_key:
225
+ rubygems_version: 3.0.3
226
+ signing_key:
227
227
  specification_version: 4
228
228
  summary: Active Elastic Job is a simple to use Active Job backend for Rails applications
229
229
  deployed on the Amazon Elastic Beanstalk platform.