active_elastic_job 1.3.0 → 1.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fba8dc34fccb06d74d63d72b215251bbd5360dc9
|
4
|
+
data.tar.gz: c3b74c2041ce300b43aec6a4415b95f8bc74608e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c73e6686338a3f38d7485526a49b8c78c3d3e49cccea3d82d56a2de044a02c6068268f762bfa13488e9f9105082b3012b374d6d24fc46e998d25b07345acad1c
|
7
|
+
data.tar.gz: 2a05f3454b9ee41148e45f0ed1c9a02192a051ba5fd7a5bf69503fa5fba7b73ce1d175f2e4f9e9b47b715d4567164b2b2e8777cab1172ea36e6bb66ec504c3e4
|
data/lib/active_elastic_job.rb
CHANGED
@@ -5,6 +5,8 @@ require 'active_job/queue_adapters/active_elastic_job_adapter'
|
|
5
5
|
require 'active_elastic_job/rack/sqs_message_consumer'
|
6
6
|
require 'active_elastic_job/message_verifier'
|
7
7
|
|
8
|
-
module ActiveElasticJob
|
8
|
+
module ActiveElasticJob
|
9
|
+
ACRONYM = 'AEJ'.freeze
|
10
|
+
end
|
9
11
|
|
10
12
|
require "active_elastic_job/railtie" if defined? Rails
|
@@ -13,7 +13,12 @@ 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'
|
16
|
+
USER_AGENT_PREFIX = 'aws-sqsd'.freeze
|
17
|
+
DIGEST_HEADER_NAME = 'HTTP_X_AWS_SQSD_ATTR_MESSAGE_DIGEST'.freeze
|
18
|
+
ORIGIN_HEADER_NAME = 'HTTP_X_AWS_SQSD_ATTR_ORIGIN'.freeze
|
19
|
+
CONTENT_TYPE = 'application/json'.freeze
|
20
|
+
CONTENT_TYPE_HEADER_NAME = 'Content-Type'.freeze
|
21
|
+
OK_RESPONSE_CODE = '200'.freeze
|
17
22
|
|
18
23
|
def initialize(app) #:nodoc:
|
19
24
|
@app = app
|
@@ -27,11 +32,11 @@ module ActiveElasticJob
|
|
27
32
|
job = JSON.load(request.body)
|
28
33
|
ActiveJob::Base.execute(job)
|
29
34
|
rescue ActiveElasticJob::MessageVerifier::InvalidDigest => e
|
30
|
-
return ['403', {
|
35
|
+
return ['403', {CONTENT_TYPE_HEADER_NAME => env['text/plain'] }, ["incorrect digest"]]
|
31
36
|
rescue StandardError => e
|
32
|
-
return ['500', {
|
37
|
+
return ['500', {CONTENT_TYPE_HEADER_NAME => env['text/plain'] }, [e.message]]
|
33
38
|
end
|
34
|
-
return [
|
39
|
+
return [OK_RESPONSE_CODE , {CONTENT_TYPE_HEADER_NAME => CONTENT_TYPE }, [ '' ]]
|
35
40
|
end
|
36
41
|
@app.call(env)
|
37
42
|
end
|
@@ -41,7 +46,7 @@ module ActiveElasticJob
|
|
41
46
|
def verify!(request)
|
42
47
|
secret_key_base = Rails.application.secrets[:secret_key_base]
|
43
48
|
@verifier ||= ActiveElasticJob::MessageVerifier.new(secret_key_base)
|
44
|
-
digest = request.headers[
|
49
|
+
digest = request.headers[DIGEST_HEADER_NAME]
|
45
50
|
@verifier.verify!(request.body.string, digest)
|
46
51
|
end
|
47
52
|
|
@@ -51,14 +56,20 @@ module ActiveElasticJob
|
|
51
56
|
# Instead we make a simple string comparison.
|
52
57
|
# Benchmark runs showed an performance increase of
|
53
58
|
# up to 40%
|
54
|
-
current_user_agent = request.headers['User-Agent']
|
59
|
+
current_user_agent = request.headers['User-Agent'.freeze]
|
55
60
|
return (current_user_agent.present? &&
|
56
61
|
current_user_agent.size >= USER_AGENT_PREFIX.size &&
|
57
62
|
current_user_agent[0..(USER_AGENT_PREFIX.size - 1)] == USER_AGENT_PREFIX)
|
58
63
|
end
|
59
64
|
|
60
65
|
def originates_from_gem?(request)
|
61
|
-
request.headers[
|
66
|
+
if request.headers[ORIGIN_HEADER_NAME] == ActiveElasticJob::ACRONYM
|
67
|
+
return true
|
68
|
+
elsif request.headers[DIGEST_HEADER_NAME] != nil
|
69
|
+
return true
|
70
|
+
else
|
71
|
+
return false
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
64
75
|
end
|
@@ -77,24 +77,10 @@ The message with Message ID #{message_id} sent to SQS might be corrupted.
|
|
77
77
|
def enqueue_at(job, timestamp) #:nodoc:
|
78
78
|
serialized_job = JSON.dump(job.serialize)
|
79
79
|
check_job_size!(serialized_job)
|
80
|
-
message =
|
81
|
-
queue_url: queue_url(job.queue_name),
|
82
|
-
message_body: serialized_job,
|
83
|
-
delay_seconds: calculate_delay(timestamp),
|
84
|
-
message_attributes: {
|
85
|
-
"message_digest" => {
|
86
|
-
string_value: message_digest(serialized_job),
|
87
|
-
data_type: "String"
|
88
|
-
},
|
89
|
-
"origin" => {
|
90
|
-
string_value: "AEJ",
|
91
|
-
data_type: "String"
|
92
|
-
}
|
93
|
-
}
|
94
|
-
}
|
80
|
+
message = build_message(job.queue_name, serialized_job, timestamp)
|
95
81
|
resp = aws_sqs_client.send_message(message)
|
96
82
|
verify_md5_digests!(
|
97
|
-
|
83
|
+
resp,
|
98
84
|
message[:message_body],
|
99
85
|
message[:message_attributes]
|
100
86
|
)
|
@@ -110,6 +96,24 @@ The message with Message ID #{message_id} sent to SQS might be corrupted.
|
|
110
96
|
|
111
97
|
private
|
112
98
|
|
99
|
+
def build_message(queue_name, serialized_job, timestamp)
|
100
|
+
{
|
101
|
+
queue_url: queue_url(queue_name),
|
102
|
+
message_body: serialized_job,
|
103
|
+
delay_seconds: calculate_delay(timestamp),
|
104
|
+
message_attributes: {
|
105
|
+
message_digest: {
|
106
|
+
string_value: message_digest(serialized_job),
|
107
|
+
data_type: "String".freeze
|
108
|
+
},
|
109
|
+
origin: {
|
110
|
+
string_value: ActiveElasticJob::ACRONYM,
|
111
|
+
data_type: "String".freeze
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
113
117
|
def queue_url(queue_name)
|
114
118
|
cache_key = queue_name.to_s
|
115
119
|
@queue_urls ||= { }
|
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.3.
|
4
|
+
version: 1.3.1
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|