simple_message_queue 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,12 +6,16 @@ Simple Message Queue can be used by a single application for background job proc
6
6
 
7
7
  ### Setting up Simple Message Queue
8
8
 
9
- In order to use Simple Message Queue in your application, you must first configure it. In order to configure Simple Message Queue, you must call a configure block and pass at least your AWS access_key_id and secret_access_key:
9
+ In order to use Simple Message Queue in your application, you must first configure it. In order to configure Simple Message Queue, you must call a configure block and pass at least your AWS access_key_id and secret_access_key as well as the environment.
10
+
11
+ The environment variable is used to name your queues. You don't want to be using the same queue in development as in production, so the environment is required, and will be appended to your queue name (e.g. test_queue_development and test_queue_production). In a rails application you can simply use Rails.env (as shown below). If you are using Sinatra or another framework, you will probably want to use ENV['RACK_ENV'], just make sure that you set ENV['RACK_ENV'] in all of your environments or SimpleMessageQueue will throw errors.
10
12
 
11
13
  ```ruby
12
14
  SimpleMessageQueue.configure do |config|
13
15
  config.access_key_id = 'your_access_key_id'
14
16
  config.secret_access_key= 'your_secret_access_key'
17
+ config.environment = Rails.env # For Rails applications
18
+ # config.environment = ENV['RACK_ENV'] # For non-Rails applications
15
19
  end
16
20
  ```
17
21
 
@@ -23,6 +27,7 @@ You can also pass in a few other variables to the configure block such as an idl
23
27
  SimpleMessageQueue.configure do |config|
24
28
  config.access_key_id = 'your_access_key_id'
25
29
  config.secret_access_key= 'your_secret_access_key'
30
+ config.environment = Rails.env
26
31
  config.idle_timeout = 10 # optional
27
32
  config.wait_time_seconds = 20 # optional
28
33
  config.logger = Logger.new('simple_message_queue.log') # optional
@@ -43,18 +48,21 @@ end
43
48
 
44
49
  #### Queue Naming
45
50
 
46
- By default, your SQS queue will be named after the model you created (e.g. TestQueue will have a queue named test_queue). You can overwrite this in your model by adding a queue_name method to the class:
51
+ By default, your SQS queue will be named after the model you created and appended with the environment name (e.g. TestQueue in development will have a queue named test_queue_development). You can overwrite this in your model by adding a @queue_name variable to the class:
47
52
 
48
53
  ```ruby
49
54
  class TestQueue
50
55
  extend SimpleMessageQueue
51
56
 
52
- def self.queue_name
53
- 'my_new_queue_name'
54
- end
57
+ @queue_name = 'super_awesome_queue'
55
58
  end
56
59
  ```
57
60
 
61
+ This will generate a queue with the name of super_awesome_queue_development in your development environment.
62
+
63
+ **NOTE:** To prevent the same queue being used in multiple environments (which could wreak havoc with your application), the environment name is always appended to the queue_name. Although you can overwrite the queue_name method, this is a very, very bad idea (BUT if you do, please take multiple environments into account).
64
+
65
+
58
66
  #### Sending Messages
59
67
 
60
68
  In order to send a message with Simple Message Queue, simply call the following:
@@ -127,6 +135,7 @@ If you are using Simple Message Queue for background processing between sites yo
127
135
 
128
136
  **Note:** If you have multiple models receiving messages from the same queue, there is no guarantee which model will receive which message. This is why it is best to only have a single model (on a single site) receiving messages from a specific queue. If you need multiple queues, simply create multiple models with different queue_names.
129
137
 
138
+
130
139
  ## Contributing
131
140
 
132
141
  In order to contribute to this gem, please submit a pull request with passing tests.
@@ -1,6 +1,6 @@
1
1
  module SimpleMessageQueue
2
2
  class Configuration
3
- attr_accessor :access_key_id, :secret_access_key, :logger, :idle_timeout, :wait_time_seconds
3
+ attr_accessor :access_key_id, :secret_access_key, :logger, :idle_timeout, :wait_time_seconds, :environment
4
4
 
5
5
  def initialize
6
6
  @access_key_id = nil
@@ -8,6 +8,7 @@ module SimpleMessageQueue
8
8
  @logger = nil
9
9
  @idle_timeout = 10
10
10
  @wait_time_seconds = 20
11
+ @environment = nil
11
12
  end
12
13
  end
13
14
  end
@@ -2,7 +2,7 @@ module SimpleMessageQueue
2
2
 
3
3
  class ConfigurationError < StandardError
4
4
  def initialize
5
- message = "SimpleMessageQueue has not been configured. Create an initializer with a SimpleMessageQueue.configure block and set the access_key_id and secret_access_key."
5
+ message = "SimpleMessageQueue has not been configured. Create an initializer with a SimpleMessageQueue.configure block and set the access_key_id, secret_access_key and environment variable."
6
6
  super(message)
7
7
  end
8
8
  end
@@ -14,4 +14,11 @@ module SimpleMessageQueue
14
14
  end
15
15
  end
16
16
 
17
+ class EnvironmentError < StandardError
18
+ def initialize
19
+ message = "You must define the environment in the SimpleMessageQueue.configure block. Without setting the environment the same queue will be used across environments causing unwanted results."
20
+ super(message)
21
+ end
22
+ end
23
+
17
24
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleMessageQueue
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -17,11 +17,17 @@ module SimpleMessageQueue
17
17
 
18
18
  def sqs
19
19
  raise SimpleMessageQueue::ConfigurationError unless SimpleMessageQueue.configuration
20
+ raise SimpleMessageQueue::EnvironmentError unless environment_defined?
20
21
  @@sqs ||= AWS::SQS.new(:access_key_id => SimpleMessageQueue.configuration.access_key_id, :secret_access_key => SimpleMessageQueue.configuration.secret_access_key)
21
22
  end
22
23
 
23
24
  def queue_name
24
- name.underscore.gsub('/', '_')
25
+ raise SimpleMessageQueue::EnvironmentError unless environment_defined?
26
+ if @queue_name
27
+ @queue_name + "_#{SimpleMessageQueue.configuration.environment}"
28
+ else
29
+ name.underscore.gsub('/', '_') + "_#{SimpleMessageQueue.configuration.environment}"
30
+ end
25
31
  end
26
32
 
27
33
  def queue
@@ -70,4 +76,10 @@ module SimpleMessageQueue
70
76
  raise SimpleMessageQueue::NotImplementedError.new(name)
71
77
  end
72
78
 
79
+ protected
80
+
81
+ def environment_defined?
82
+ defined?(SimpleMessageQueue.configuration.environment)
83
+ end
84
+
73
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_message_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-01 00:00:00.000000000 Z
12
+ date: 2013-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
16
- requirement: &70244156709540 !ruby/object:Gem::Requirement
16
+ requirement: &70130285737680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70244156709540
24
+ version_requirements: *70130285737680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70244156709120 !ruby/object:Gem::Requirement
27
+ requirement: &70130285736440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70244156709120
35
+ version_requirements: *70130285736440
36
36
  description: SimpleMessageQueue is a simple interface for Amazon Web Service's SQS.
37
37
  email:
38
38
  - jim@jimsmithdesign.com