resque_mail_queue 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ resque_mail_queue global
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in resque_mail_queue.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ resque_mail_queue (0.0.10)
5
+ actionmailer (>= 3.0.0)
6
+ resque (>= 1.1.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.10)
13
+ actionpack (= 3.0.10)
14
+ mail (~> 2.2.19)
15
+ actionpack (3.0.10)
16
+ activemodel (= 3.0.10)
17
+ activesupport (= 3.0.10)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.5.0)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.14)
23
+ rack-test (~> 0.5.7)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.10)
26
+ activesupport (= 3.0.10)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.5.0)
29
+ activesupport (3.0.10)
30
+ builder (2.1.2)
31
+ diff-lcs (1.1.3)
32
+ erubis (2.6.6)
33
+ abstract (>= 1.0.0)
34
+ i18n (0.5.0)
35
+ mail (2.2.19)
36
+ activesupport (>= 2.3.6)
37
+ i18n (>= 0.4.0)
38
+ mime-types (~> 1.16)
39
+ treetop (~> 1.4.8)
40
+ mime-types (1.16)
41
+ multi_json (1.0.3)
42
+ polyglot (0.3.2)
43
+ rack (1.2.3)
44
+ rack-mount (0.6.14)
45
+ rack (>= 1.0.0)
46
+ rack-test (0.5.7)
47
+ rack (>= 1.0)
48
+ redis (2.2.2)
49
+ redis-namespace (1.0.3)
50
+ redis (< 3.0.0)
51
+ resque (1.19.0)
52
+ multi_json (~> 1.0)
53
+ redis-namespace (~> 1.0.2)
54
+ sinatra (>= 0.9.2)
55
+ vegas (~> 0.1.2)
56
+ resque_spec (0.7.0)
57
+ resque (>= 1.15.0)
58
+ rspec (>= 2.5.0)
59
+ rspec (2.6.0)
60
+ rspec-core (~> 2.6.0)
61
+ rspec-expectations (~> 2.6.0)
62
+ rspec-mocks (~> 2.6.0)
63
+ rspec-core (2.6.4)
64
+ rspec-expectations (2.6.0)
65
+ diff-lcs (~> 1.1.2)
66
+ rspec-mocks (2.6.0)
67
+ sinatra (1.2.6)
68
+ rack (~> 1.1)
69
+ tilt (>= 1.2.2, < 2.0)
70
+ tilt (1.3.3)
71
+ treetop (1.4.10)
72
+ polyglot
73
+ polyglot (>= 0.3.1)
74
+ tzinfo (0.3.29)
75
+ vegas (0.1.8)
76
+ rack (>= 1.0.0)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ resque_mail_queue!
83
+ resque_spec (>= 0.7.0)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,47 @@
1
+ require 'resque'
2
+ require 'action_mailer'
3
+
4
+ module Resque
5
+ module MailQueue
6
+
7
+ include Resque::Helpers
8
+ extend self
9
+
10
+ def queue
11
+ :mail
12
+ end
13
+
14
+ def perform(options = {})
15
+ mailer = constantize(options['klass'])
16
+ method = options['method']
17
+ mailer.send(method, *options['args']).deliver
18
+ end
19
+
20
+ def enqueue()
21
+ EnqueueProxy.new(self)
22
+ end
23
+
24
+ class EnqueueProxy
25
+
26
+ def initialize(klass)
27
+ @klass = klass
28
+ end
29
+
30
+ def method_missing(m, *args, &block)
31
+ if @klass.respond_to? m
32
+ options = {'klass' => @klass.to_s, 'method' => m, 'args' => args}
33
+ Resque.enqueue(@klass, options)
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ VERSION = '0.2.0'
42
+ end
43
+ end
44
+
45
+ class ActionMailer::Base
46
+ extend Resque::MailQueue
47
+ end
data/readme.md ADDED
@@ -0,0 +1,40 @@
1
+ # Resque Mail Queue
2
+
3
+ This gem makes it very easy to send emails asynchronously with [Resque](http://github.com/defunkt/resque).
4
+
5
+ ## Usage
6
+
7
+ Add the gem to your gemfile:
8
+
9
+ gem 'resque_mail_queue'
10
+
11
+ Then anytime you want to push an email asynchronously add _enqueue_ before the mailer method.
12
+
13
+ UserMailer.enqueue.welcome_email(1)
14
+
15
+ ## Notes
16
+
17
+ 1. As with most things Resque, your parameters should be simple objects (ids, strings, etc). Or put another way, do not pass your models directly.
18
+ 1. You do not have to call deliver
19
+ 1. By default, all messages will be placed on a queue called "mail". You can change this by adding a class method called queue on any mailer.
20
+
21
+ class MyMailer < ActionMailer::Base
22
+
23
+ def self.queue
24
+ :high_priority
25
+ end
26
+
27
+ end
28
+
29
+
30
+ ## Why use this instead of ResqueMailer
31
+
32
+ I initially started using [ResqueMailer](https://github.com/zapnap/resque_mailer) and it worked well. However, I preferred being more explicit (and simple) on when emails where being sent asynchronously (by calling enqueue).
33
+
34
+ More clearly, if ResqueMailer works for you and you like it, stick with it.
35
+
36
+
37
+ ## License
38
+
39
+ Provided under the Do Whatever You Want With This Code License.
40
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "resque_mail_queue"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "resque_mail_queue"
7
+ s.version = Resque::MailQueue::VERSION
8
+ s.authors = ["Scott Watermasysk"]
9
+ s.email = ["scottwater@gmail.com"]
10
+ s.homepage = "https://github.com/scottwater/resque_mail_queue"
11
+ s.summary = 'Simple asynchronous emails with Resque'
12
+ s.description = 'Simple asynchronous emails with Resque'
13
+
14
+ s.rubyforge_project = "resque_mail_queue"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'actionmailer', '>= 3.0.0'
22
+
23
+ s.add_dependency 'resque', '>= 1.1.0'
24
+ s.add_development_dependency 'resque_spec', '>= 0.7.0'
25
+
26
+ end
@@ -0,0 +1,41 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'resque_mail_queue'
3
+ require 'resque_spec'
4
+
5
+ class DumbMailer
6
+ extend Resque::MailQueue
7
+ def self.send_mail(user_id)
8
+ end
9
+ end
10
+
11
+ class DumbMailer2 < DumbMailer
12
+ def self.queue
13
+ :not_default
14
+ end
15
+ end
16
+
17
+
18
+ describe Resque::MailQueue do
19
+
20
+ before(:each) do
21
+ ResqueSpec.reset!
22
+ end
23
+
24
+ it 'should find a dummy mail in the default queue' do
25
+ DumbMailer.enqueue.send_mail(3)
26
+ DumbMailer.should have_queued('klass' => 'DumbMailer', 'method' => :send_mail, 'args' => [3]).in(:default)
27
+ end
28
+
29
+ it 'should be able to override the queue (not default)' do
30
+ DumbMailer2.enqueue.send_mail(3)
31
+ DumbMailer2.should have_queued('klass' => 'DumbMailer2', 'method'=> :send_mail, 'args' => [3]).in(:not_default)
32
+
33
+ end
34
+
35
+ it 'should call deliver when pulling an item from the queue' do
36
+ mail_message = double('mail_message')
37
+ DumbMailer.stub(:send_mail).and_return(mail_message)
38
+ mail_message.should_receive(:deliver)
39
+ Resque::MailQueue.perform('klass' => 'DumbMailer', 'method' => :send_mail, 'args' => [3])
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_mail_queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Watermasysk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionmailer
16
+ requirement: &70272696466380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70272696466380
25
+ - !ruby/object:Gem::Dependency
26
+ name: resque
27
+ requirement: &70272696464360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70272696464360
36
+ - !ruby/object:Gem::Dependency
37
+ name: resque_spec
38
+ requirement: &70272696463180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.7.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70272696463180
47
+ description: Simple asynchronous emails with Resque
48
+ email:
49
+ - scottwater@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rbenv-gemsets
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - Rakefile
59
+ - lib/resque_mail_queue.rb
60
+ - readme.md
61
+ - resque_mail_queue.gemspec
62
+ - spec/resque_mail_queue_spec.rb
63
+ homepage: https://github.com/scottwater/resque_mail_queue
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project: resque_mail_queue
83
+ rubygems_version: 1.8.7
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Simple asynchronous emails with Resque
87
+ test_files:
88
+ - spec/resque_mail_queue_spec.rb