mandrill_queue 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +7 -3
- data/lib/mandrill_queue/adapters/resque_adapter.rb +15 -2
- data/lib/mandrill_queue/adapters/sidekiq_adapter.rb +10 -2
- data/lib/mandrill_queue/configuration.rb +1 -1
- data/lib/mandrill_queue/mailer.rb +8 -2
- data/lib/mandrill_queue/version.rb +1 -1
- data/lib/mandrill_queue.rb +14 -10
- data/lib/rails/generators/mandrill_queue/templates/initializer.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d51589640920eb3e6f0adc4a4216b56bf018a6a3
|
4
|
+
data.tar.gz: 734ac1825282bd142a07b3206341cf5092ff6ddc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18e64f5f2569a7a647f82b28496aa1a3a29536a5f39ffbe94903db5c0732434094b55d228f01a268db91ad76f17a8f5ffcc3b347c74874efc110200c5d7cca30
|
7
|
+
data.tar.gz: f8c468c62f2761a70ccfa63d80fb692770619d8a1f8626383216a32bf32d506938b1baa2a1956408d4d93d4797b0de39202981837f5f8829330481e17ddf28c1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -117,7 +117,9 @@ This can be added anywhere like a Rails controller or Sinatra endpoint.
|
|
117
117
|
|
118
118
|
You probably already know this bit:
|
119
119
|
|
120
|
-
gem '
|
120
|
+
gem 'sidekiq'
|
121
|
+
# or
|
122
|
+
# gem 'resque'
|
121
123
|
gem 'mandrill_queue'
|
122
124
|
|
123
125
|
but didn't know this (but it's optional):
|
@@ -149,6 +151,7 @@ but here's a taster:
|
|
149
151
|
# NEEDED FOR WORKER ONLY
|
150
152
|
# Mandrill api key needed for worker only
|
151
153
|
config.api_key = 'xxxxxx'
|
154
|
+
config.adapter = MyQueueAdapter # or just :sidekiq / :resque
|
152
155
|
config.default_worker_class = MyWorker
|
153
156
|
config.default_queue = :hipster_queue
|
154
157
|
end
|
@@ -221,8 +224,9 @@ end
|
|
221
224
|
|
222
225
|
## TODO
|
223
226
|
|
224
|
-
1.
|
225
|
-
2.
|
227
|
+
1. NB! Change DSL to pass in arguments to blocks so that the class context is still accessible within them.
|
228
|
+
2. Render ActionView views to mailers.
|
229
|
+
3. Allow synchonous sending.
|
226
230
|
|
227
231
|
## Contributing
|
228
232
|
|
@@ -1,8 +1,21 @@
|
|
1
1
|
module MandrillQueue
|
2
2
|
module Adapters
|
3
3
|
class ResqueAdapter
|
4
|
-
def enqueue_to(queue, klass, *args)
|
5
|
-
|
4
|
+
def enqueue_to(queue, klass, options, *args)
|
5
|
+
if options.key?(:send_at)
|
6
|
+
check_for_scheduler!
|
7
|
+
Resque.enqueue_at_with_queue(queue, options[:send_at], klass, *args)
|
8
|
+
elsif options.key?(:send_in)
|
9
|
+
check_for_scheduler!
|
10
|
+
Resque.enqueue_in_with_queue(queue, options[:send_in], klass, *args)
|
11
|
+
else
|
12
|
+
::Resque.enqueue_to(queue, klass, *args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_for_scheduler!
|
17
|
+
raise RuntimeError, "Please install resque-scheduler to allow scheduled jobs!" \
|
18
|
+
unless ::Resque.respond_to?(:enqueue_in)
|
6
19
|
end
|
7
20
|
end
|
8
21
|
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
module MandrillQueue
|
2
2
|
module Adapters
|
3
3
|
class SidekiqAdapter
|
4
|
-
def enqueue_to(queue, klass, *args)
|
5
|
-
::Sidekiq::Client
|
4
|
+
def enqueue_to(queue, klass, options, *args)
|
5
|
+
client = ::Sidekiq::Client
|
6
|
+
|
7
|
+
if options.key?(:send_at)
|
8
|
+
client.enqueue_to_in(queue, options[:send_at], klass, *args)
|
9
|
+
elsif options.key?(:send_in)
|
10
|
+
client.enqueue_to_in(queue, options[:send_in], klass, *args)
|
11
|
+
else
|
12
|
+
client.enqueue_to(queue, klass, *args)
|
13
|
+
end
|
6
14
|
end
|
7
15
|
end
|
8
16
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module MandrillQueue
|
2
2
|
class Configuration
|
3
3
|
ACCESSORS = [:message_defaults, :resque, :default_worker_class,
|
4
|
-
:default_queue, :api_key, :logger, :adapter]
|
4
|
+
:default_queue, :api_key, :logger, :adapter, :adapter_options]
|
5
5
|
attr_accessor(*ACCESSORS)
|
6
6
|
|
7
7
|
def initialize(defaults = {}, &block)
|
@@ -81,6 +81,7 @@ module MandrillQueue
|
|
81
81
|
|
82
82
|
def initialize(values = nil)
|
83
83
|
set!(values) unless values.nil?
|
84
|
+
@_adapter_options = self.class.configuration.adapter_options || {}
|
84
85
|
end
|
85
86
|
|
86
87
|
def reset!
|
@@ -133,9 +134,14 @@ module MandrillQueue
|
|
133
134
|
|
134
135
|
def deliver
|
135
136
|
validate!
|
136
|
-
MandrillQueue.adapter.enqueue_to(queue, worker_class, to_hash)
|
137
|
+
MandrillQueue.adapter.enqueue_to(queue, worker_class, adapter_options, to_hash)
|
137
138
|
end
|
138
139
|
|
140
|
+
def adapter_options(options = nil)
|
141
|
+
@_adapter_options.merge!(options) unless options.nil?
|
142
|
+
@_adapter_options ||= {}
|
143
|
+
end
|
144
|
+
|
139
145
|
def to_hash(options = {})
|
140
146
|
hash = {}
|
141
147
|
ACCESSORS.each do |key|
|
@@ -145,7 +151,7 @@ module MandrillQueue
|
|
145
151
|
|
146
152
|
hash[:message] = message.to_hash(options) rescue nil if !@_message.nil? || options[:include_nils]
|
147
153
|
hash[:content] = content.to_key_value_array(options) rescue nil if !@_content.nil? || options[:include_nils]
|
148
|
-
|
154
|
+
hash
|
149
155
|
end
|
150
156
|
|
151
157
|
def set!(hash)
|
data/lib/mandrill_queue.rb
CHANGED
@@ -5,6 +5,8 @@ require 'mandrill_queue/configuration'
|
|
5
5
|
require 'mandrill_queue/mailer'
|
6
6
|
|
7
7
|
module MandrillQueue
|
8
|
+
@@lock = Mutex.new
|
9
|
+
|
8
10
|
def self.configuration
|
9
11
|
@configuration ||= Configuration.new(defaults)
|
10
12
|
end
|
@@ -33,18 +35,20 @@ module MandrillQueue
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def self.adapter
|
36
|
-
|
37
|
-
|
38
|
-
adapter =
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
@@lock.synchronize do
|
39
|
+
@_adapter ||= begin
|
40
|
+
unless adapter = configuration.adapter
|
41
|
+
adapter = :resque if defined(::Resque)
|
42
|
+
adapter = :sidekiq if defined(::Sidekiq)
|
43
|
+
if adapter.nil?
|
44
|
+
raise RuntimeError, <<-TXT.strip.tr("\t", '')
|
45
|
+
Worker adapter was not configured and cannot be determined.
|
46
|
+
Please include a worker gem in your Gemfile. Resque and Sidekiq are supported.
|
47
|
+
TXT
|
48
|
+
end
|
45
49
|
end
|
50
|
+
load_adapter(adapter)
|
46
51
|
end
|
47
|
-
load_adapter(adapter)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
@@ -41,4 +41,9 @@ MandrillQueue.configure do |config|
|
|
41
41
|
# Used to set the current logger. This can be any object
|
42
42
|
# that responds to debug, info, warn, error and fatal
|
43
43
|
# config.logger = MyLoggingClass
|
44
|
+
#
|
45
|
+
# Default options passed through to the queue adapter
|
46
|
+
# These options can mean different things depending on
|
47
|
+
# which adapter you choose.
|
48
|
+
# config.adapter_options = {}
|
44
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandrill_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stan Bondi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|