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: 8b6ddee2978dadb7583fd3b80029db16237e9379
4
- data.tar.gz: 221f7ad5ad3392531f2d58ec84471f9fe4c56650
3
+ metadata.gz: 2c8395a6c3ac158c58cf57615c9df6bbe847ea76
4
+ data.tar.gz: 33b4188334606d4df92dd4fff85e2fc6a5558629
5
5
  SHA512:
6
- metadata.gz: 6eea93a2f8921038c6118be8f4d47ac64bd24562b07f101419b42c3e3d18fc62e268eab03cab883637ee6f130b581538436dc77a1760bff89edc0d7a754d6ce9
7
- data.tar.gz: 5a28a30592122b6f16a68dce3c865ac217954fcabe3658770918ac1dea8e51d13684feb53ca305fadbca97524955bc104ca59483f5aeda584c50e3af0033fe17
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 => env['text/plain'] }, ["incorrect digest"]]
39
+ return ['403', {CONTENT_TYPE_HEADER_NAME => 'text/plain' }, ["incorrect digest"]]
36
40
  rescue StandardError => e
37
- return ['500', {CONTENT_TYPE_HEADER_NAME => env['text/plain'] }, [e.message]]
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)
@@ -1,8 +1,8 @@
1
1
  module ActiveElasticJob
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 3
5
- TINY = 3
4
+ MINOR = 4
5
+ TINY = 0
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -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 > 15.minutes
130
+ if delay > MAX_DELAY_IN_MINUTES.minutes
130
131
  msg =<<-MSG
131
- Jobs cannot be scheduled more than 15 minutes into the future.
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, msg if delay > 15.minutes
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 = ActiveElasticJob::MessageVerifier.new(secret_key_base)
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.3.3
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-14 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk