active_elastic_job 1.1.0 → 1.2.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: c9ced62a0162f40de919760ea5563c6bf6e6417e
4
- data.tar.gz: 182d2fc41d98ee5fce356190e7ece9aa6d85e449
3
+ metadata.gz: a7920ea5a8cddd9a08241262d501ce3e35023fb0
4
+ data.tar.gz: 60c134bbb660447bbabd3a9082e2946d896efa4c
5
5
  SHA512:
6
- metadata.gz: 4f7f9614d11eac062792ff694ca57a2d598f9abd882d42cdfab6fdbd538c171783a14b7f9467de56745c29c6c8688440e08c48b7cd87e19e54ca34c7a8c7b204
7
- data.tar.gz: 9871d65f4264d52d4f13d1858093ce2e7de4929f76925f22dfb014be2a5c33370e9c1259486a645ea86bed660f0707ca60b98ac483d9bb820eccc25b943d7ef6
6
+ metadata.gz: 839ad7a954dfe1580b1dc39fda59f32997a36342005304c278fc4c2c8601924dde28199775d1c7f3e9d67fd7067669f3b060fdfe99ef68f9ce4be43a55991ead
7
+ data.tar.gz: 8165acdb80c9143b23fa50eb9c3407549f9d4b7d828630afc6f48fb166dcb9392a5b12be4ed556a8f277fb179afcd5fb838224bd9ff724e77380aa904eb4326f
@@ -22,11 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.required_ruby_version = '>= 1.9.3'
24
24
 
25
- spec.add_development_dependency 'bundler'
26
- spec.add_development_dependency 'rspec', '~> 3.4'
27
- spec.add_development_dependency 'dotenv'
28
- spec.add_development_dependency 'fuubar'
29
- spec.add_development_dependency 'rails', '~> 4.2'
30
- spec.add_development_dependency 'rdoc'
31
25
  spec.add_dependency 'aws-sdk', '~> 2'
26
+ spec.add_dependency 'rails', '~> 4.2'
32
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveElasticJob
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -14,31 +14,69 @@ module ActiveJob
14
14
  #
15
15
  # Rails.application.config.active_job.queue_adapter = :active_elastic_job
16
16
  class ActiveElasticJobAdapter
17
+ MAX_MESSAGE_SIZE = (256 * 1024)
18
+
19
+ class Error < StandardError; end;
20
+
21
+ class SerializedJobTooBig < Error
22
+ def initialize(serialized_job)
23
+ msg = <<-MSG
24
+ The job contains #{serialized_job.bytesize} bytes in its serialzed form,
25
+ which exceeds the allowed maximum of #{MAX_MESSAGE_SIZE} bytes imposed by Amazon SQS.
26
+ MSG
27
+ super msg
28
+ end
29
+ end
30
+
31
+ # Raised when job queue does not exist. The job queue is determined
32
+ # <tt>ActiveJob::Base.queue_as</tt>. You can either: (1) create a new Amazon
33
+ # SQS queue and attach a worker enviroment to it, or (2) select a different
34
+ # queue for your jobs.
35
+ #
36
+ # Example:
37
+ # * Open your AWS console and create an SQS queue named +high_priority+ in
38
+ # the same AWS region of your Elastic Beanstalk environments.
39
+ # * Queue your jobs accordingly:
40
+ #
41
+ # class MyJob < ActiveJob::Base
42
+ # queue_as :high_priority
43
+ # #..
44
+ # end
45
+ class NonExistentQueue < Error
46
+ def initialize(job)
47
+ msg = <<-MSG
48
+ The job is bound to queue at #{job.queue_name}. Unfortunately a queue
49
+ with this name does not exist in this region. Either create an Amazon SQS queue
50
+ named #{job.queue_name} - you can do this in AWS console, make sure to select
51
+ region '#{ENV['AWS_REGION']}' - or you select another queue for
52
+ #{job.class.name} jobs.
53
+ MSG
54
+ super msg
55
+ end
56
+ end
57
+
17
58
  class << self
18
59
  def enqueue(job) #:nodoc:
19
60
  enqueue_at(job, Time.now)
20
61
  end
21
62
 
22
63
  def enqueue_at(job, timestamp) #:nodoc:
23
- queue_url = aws_sqs_client.create_queue(queue_name: job.queue_name.to_s).queue_url
24
- message_body = JSON.dump(job.serialize)
25
- delay = (timestamp - Time.current.to_f).to_i + 1
26
- if delay > 15.minutes
27
- msg =<<-MSG
28
- Jobs cannot be scheduled more than 15 minutes into the future.
29
- See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
30
- for further details!
31
- MSG
32
- raise RangeError, msg if delay > 15.minutes
64
+ queue_url = nil
65
+ begin
66
+ resp = aws_sqs_client.get_queue_url(queue_name: job.queue_name.to_s)
67
+ queue_url = resp.queue_url
68
+ rescue Aws::SQS::Errors::NonExistentQueue => e
69
+ raise NonExistentQueue, job
33
70
  end
34
-
71
+ serialized_job = JSON.dump(job.serialize)
72
+ check_job_size!(serialized_job)
35
73
  aws_sqs_client.send_message(
36
74
  queue_url: queue_url,
37
- message_body: message_body,
38
- delay_seconds: delay,
75
+ message_body: serialized_job,
76
+ delay_seconds: calculate_delay(timestamp),
39
77
  message_attributes: {
40
78
  "message_digest" => {
41
- string_value: message_digest(message_body),
79
+ string_value: message_digest(serialized_job),
42
80
  data_type: "String"
43
81
  }
44
82
  }
@@ -47,6 +85,25 @@ module ActiveJob
47
85
 
48
86
  private
49
87
 
88
+ def calculate_delay(timestamp)
89
+ delay = (timestamp - Time.current.to_f).to_i + 1
90
+ if delay > 15.minutes
91
+ msg =<<-MSG
92
+ Jobs cannot be scheduled more than 15 minutes into the future.
93
+ See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
94
+ for further details!
95
+ MSG
96
+ raise RangeError, msg if delay > 15.minutes
97
+ end
98
+ delay
99
+ end
100
+
101
+ def check_job_size!(serialized_job)
102
+ if serialized_job.bytesize > MAX_MESSAGE_SIZE
103
+ raise SerializedJobTooBig, serialized_job
104
+ end
105
+ end
106
+
50
107
  def aws_sqs_client
51
108
  Aws::SQS::Client.new(
52
109
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
metadata CHANGED
@@ -1,71 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_elastic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.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-06 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
14
+ name: aws-sdk
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '3.4'
34
- type: :development
19
+ version: '2'
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '3.4'
41
- - !ruby/object:Gem::Dependency
42
- name: dotenv
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: fuubar
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
26
+ version: '2'
69
27
  - !ruby/object:Gem::Dependency
70
28
  name: rails
71
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,41 +31,13 @@ dependencies:
73
31
  - - "~>"
74
32
  - !ruby/object:Gem::Version
75
33
  version: '4.2'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '4.2'
83
- - !ruby/object:Gem::Dependency
84
- name: rdoc
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: aws-sdk
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '2'
104
34
  type: :runtime
105
35
  prerelease: false
106
36
  version_requirements: !ruby/object:Gem::Requirement
107
37
  requirements:
108
38
  - - "~>"
109
39
  - !ruby/object:Gem::Version
110
- version: '2'
40
+ version: '4.2'
111
41
  description: Active Elastic Job is a simple to use Active Job backend for Rails applications
112
42
  deployed on the Amazon Elastic Beanstalk platform.
113
43
  email: