resque_delivery 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ Gemfile.lock
11
+
12
+ *.swp
13
+ *.DS_Store
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # ResqueDelivery
2
+
3
+ This gem is a library that lets you easily integrate ActionMailer with Resque. It allows you to replace your application's delivery method with a Resque backed asynchronous job.
4
+
5
+ This allows you to avoid mail delivery exception handling throughout your app. Additionally, you can retry delivery programatically via `resque-retry` or manually.
6
+
7
+ ## Installation
8
+
9
+ In your Gemfile:
10
+
11
+ ``` ruby
12
+ gem 'resque_delivery'
13
+ ```
14
+
15
+ In your `config/environments/[RAILS_ENV].rb:`
16
+
17
+ ``` ruby
18
+ config.action_mailer.resque_delivery_settings = {
19
+ :delivery_method => :smtp # your real delivery method
20
+ }
21
+ ```
22
+
23
+ It's that simple. Your Mailer.mail_name(params).deliver will now queue the Resque job for sending that email.
24
+
25
+ ## Additional Configuration
26
+
27
+ You can configure 2 additional options in your resque_delivery_settings hash:
28
+
29
+ * :queue - which resque queue to place the job in
30
+ * :job_class - (String or Class) - The job that will be queued. It is recommended that you inherit from the `ResqueDelivery::SendMail` class.
31
+
32
+ ## Notes
33
+
34
+ We serialize the Mail::Message object (via to_yaml and from_yaml) so that you can pass objects to your Mailer classes. Other similar
35
+ implementations of asynchronous mailing, queue the Mailer name with the mail parameters, building the email parts at send time. This
36
+ implementation allows our workers to be unaware of any data models or views that are required to build the email. Additionally, no further
37
+ code changes are required to make your mails asynchronous (well, assuming you already have Resque configured).
38
+
39
+ ## Changelog
40
+
41
+ * 0.0.1 - Initial Version
@@ -0,0 +1,45 @@
1
+ class ResqueDelivery
2
+ class SettingsError < ArgumentError; end
3
+
4
+ attr_reader :delivery_method, :queue, :job_class
5
+
6
+ def initialize(options)
7
+ @delivery_method = options[:delivery_method]
8
+ @queue = options[:queue] || :medium
9
+ @job_class = options[:job_class] || SendMail
10
+ @job_class = @job_class.constantize if @job_class.is_a?(String)
11
+
12
+ @job_class.instance_variable_set(:@queue, @queue)
13
+
14
+ raise SettingsError, "you must specify config.action_mailer.resque_delivery_settings to contain a :delivery_method" unless @delivery_method
15
+ end
16
+
17
+ def deliver!(mail)
18
+ # serialize the mail object for later sending
19
+ Resque.enqueue_to(queue, job_class, delivery_method, mail.to_yaml)
20
+ end
21
+
22
+ class SendMail
23
+ @queue = :medium
24
+
25
+ class << self
26
+ def perform(delivery_method, mail_yaml)
27
+ real_delivery_method(delivery_method).deliver!(build_message(mail_yaml))
28
+ end
29
+ protected
30
+
31
+ # deserialize the mail object
32
+ def build_message(mail_yaml)
33
+ Mail::Message.from_yaml(mail_yaml)
34
+ end
35
+
36
+ def real_delivery_method(delivery_method)
37
+ settings = ActionMailer::Base.send(:"#{delivery_method}_settings")
38
+ ActionMailer::Base.delivery_methods[delivery_method.to_sym].new(settings)
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ ActionMailer::Base.add_delivery_method(:resque_delivery, ResqueDelivery)
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = %q{resque_delivery}
3
+ gem.authors = ["Jeff Ching"]
4
+ gem.date = %q{2012-10-15}
5
+ gem.description = %q{With ResqueDelivery, you can send ActionMailer messages asynchronously with Resque.}
6
+ gem.summary = "Basic asynchronous ActionMailer delivery through Resque."
7
+ gem.email = %q{ching.jeff@gmail.com}
8
+ gem.homepage = 'http://github.com/chingor13/resque_delivery'
9
+
10
+ gem.add_runtime_dependency 'actionmailer', '~> 3.0'
11
+ gem.add_runtime_dependency 'resque'
12
+
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.name = "resque_delivery"
17
+ gem.require_paths = ['lib']
18
+ gem.version = "0.0.1"
19
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_delivery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Ching
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionmailer
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: resque
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: With ResqueDelivery, you can send ActionMailer messages asynchronously
47
+ with Resque.
48
+ email: ching.jeff@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - README.md
55
+ - lib/resque_delivery.rb
56
+ - resque_delivery.gemspec
57
+ homepage: http://github.com/chingor13/resque_delivery
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Basic asynchronous ActionMailer delivery through Resque.
81
+ test_files: []