active_elastic_job 1.3.3 → 1.4.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c8395a6c3ac158c58cf57615c9df6bbe847ea76
|
4
|
+
data.tar.gz: 33b4188334606d4df92dd4fff85e2fc6a5558629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53f0f7464e92f180bbd19af890a8069dbecafab7032865c4eb8f83052c7f01a3497c83383e023c996097875c4208fb70b1274e83e868fb80d50257eaeb53390
|
7
|
+
data.tar.gz: 44fab25e6c687772f19b01816ee56f94ccefc06e517a541b5aad1363f9a72f289d6a65713f5e663d89a7dda86844d070ca5ad8e4c3f0670b93102b5760958e17
|
@@ -26,15 +26,19 @@ module ActiveElasticJob
|
|
26
26
|
|
27
27
|
def call(env) #:nodoc:
|
28
28
|
request = ActionDispatch::Request.new env
|
29
|
-
if aws_sqsd?(request) && originates_from_gem?(request)
|
29
|
+
if enabled? && aws_sqsd?(request) && originates_from_gem?(request)
|
30
|
+
unless request.local?
|
31
|
+
m = "Accepts only requests from localhost for job processing".freeze
|
32
|
+
return ['403', {CONTENT_TYPE_HEADER_NAME => 'text/plain' }, [ m ]]
|
33
|
+
end
|
30
34
|
begin
|
31
35
|
verify!(request)
|
32
36
|
job = JSON.load(request.body)
|
33
37
|
ActiveJob::Base.execute(job)
|
34
38
|
rescue ActiveElasticJob::MessageVerifier::InvalidDigest => e
|
35
|
-
return ['403', {CONTENT_TYPE_HEADER_NAME =>
|
39
|
+
return ['403', {CONTENT_TYPE_HEADER_NAME => 'text/plain' }, ["incorrect digest"]]
|
36
40
|
rescue StandardError => e
|
37
|
-
return ['500', {CONTENT_TYPE_HEADER_NAME =>
|
41
|
+
return ['500', {CONTENT_TYPE_HEADER_NAME => 'text/plain' }, [e.message]]
|
38
42
|
end
|
39
43
|
return [OK_RESPONSE_CODE , {CONTENT_TYPE_HEADER_NAME => CONTENT_TYPE }, [ '' ]]
|
40
44
|
end
|
@@ -43,6 +47,11 @@ module ActiveElasticJob
|
|
43
47
|
|
44
48
|
private
|
45
49
|
|
50
|
+
def enabled?
|
51
|
+
var = ENV['DISABLE_SQS_CONSUMER'.freeze]
|
52
|
+
var == nil || var == 'false'.freeze
|
53
|
+
end
|
54
|
+
|
46
55
|
def verify!(request)
|
47
56
|
secret_key_base = Rails.application.secrets[:secret_key_base]
|
48
57
|
@verifier ||= ActiveElasticJob::MessageVerifier.new(secret_key_base)
|
@@ -15,6 +15,7 @@ module ActiveJob
|
|
15
15
|
# Rails.application.config.active_job.queue_adapter = :active_elastic_job
|
16
16
|
class ActiveElasticJobAdapter
|
17
17
|
MAX_MESSAGE_SIZE = (256 * 1024)
|
18
|
+
MAX_DELAY_IN_MINUTES = 15
|
18
19
|
|
19
20
|
extend ActiveElasticJob::MD5MessageDigestCalculation
|
20
21
|
|
@@ -126,15 +127,14 @@ The message with Message ID #{message_id} sent to SQS might be corrupted.
|
|
126
127
|
|
127
128
|
def calculate_delay(timestamp)
|
128
129
|
delay = (timestamp - Time.current.to_f).to_i + 1
|
129
|
-
if delay >
|
130
|
+
if delay > MAX_DELAY_IN_MINUTES.minutes
|
130
131
|
msg =<<-MSG
|
131
|
-
Jobs cannot be scheduled more than
|
132
|
+
Jobs cannot be scheduled more than #{MAX_DELAY_IN_MINUTES} minutes into the future.
|
132
133
|
See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
|
133
134
|
for further details!
|
134
135
|
MSG
|
135
|
-
raise RangeError
|
136
|
+
raise RangeError
|
136
137
|
end
|
137
|
-
delay = 0 if delay < 0
|
138
138
|
delay
|
139
139
|
end
|
140
140
|
|
@@ -145,7 +145,7 @@ for further details!
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def aws_sqs_client
|
148
|
-
Aws::SQS::Client.new(
|
148
|
+
@aws_sqs_client ||= Aws::SQS::Client.new(
|
149
149
|
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
150
150
|
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
|
151
151
|
region: ENV['AWS_REGION']
|
@@ -154,8 +154,8 @@ for further details!
|
|
154
154
|
|
155
155
|
def message_digest(messsage_body)
|
156
156
|
secret_key_base = Rails.application.secrets[:secret_key_base]
|
157
|
-
verifier
|
158
|
-
verifier.generate_digest(messsage_body)
|
157
|
+
@verifier ||= ActiveElasticJob::MessageVerifier.new(secret_key_base)
|
158
|
+
@verifier.generate_digest(messsage_body)
|
159
159
|
end
|
160
160
|
|
161
161
|
def verify_md5_digests!(response, messsage_body, message_attributes = nil)
|
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.
|
4
|
+
version: 1.4.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-02-
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|