dmantilla-aws_sqs_mail 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Daniel Mantilla
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
17
+ NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,21 @@
1
+ h1. Amazon Simple Queue and ActionMailer
2
+
3
+ h2. Requirements
4
+
5
+ Requires RightAws Gem http://rightscale.rubyforge.org/right_aws_gem_doc/
6
+
7
+ h2. Adding mails to the queue
8
+
9
+ <code>
10
+ FeedbackNotifier.enqueue(MAIL_QUEUE, :alert, @feedback)
11
+ </code>
12
+
13
+ h2. Delivering mails
14
+
15
+ <code>
16
+ AwsSqs::Mail.process(MAIL_QUEUE)
17
+ </code>
18
+
19
+ h2. Versions
20
+
21
+ * 0.1.0: Initial release
@@ -0,0 +1,25 @@
1
+ #version = File.read('README.textile').scan(/^\*\s+([\d\.]+)/).flatten
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "aws_sqs_mail"
5
+ s.version = "0.1.1"
6
+ s.date = "2009-07-29"
7
+ s.summary = "Adds an enqueue method to ActionMailer::Base, this adds the message to Amazon SQS which can be delivered later"
8
+ s.email = "daniel@celect.org"
9
+ s.homepage = "http://github.com/dmantilla/aws_sqs_mail/tree/master"
10
+ s.description = "Uses Amazon SQS to enqueue messages and then deliver them at a later time"
11
+ s.authors = ["Daniel Mantilla"]
12
+
13
+ s.has_rdoc = false
14
+ s.rdoc_options = ["--main", "README.textile"]
15
+ s.extra_rdoc_files = ["README.textile"]
16
+
17
+ # run git ls-files to get an updated list
18
+ s.files = %w[
19
+ MIT-LICENSE
20
+ README.textile
21
+ aws_sqs_mail.gemspec
22
+ init.rb
23
+ lib/aws_sqs_mail.rb
24
+ ]
25
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'right_aws'
2
+ require File.dirname(__FILE__) + '/lib/aws_sqs_mail'
3
+
@@ -0,0 +1,62 @@
1
+ module ActionMailer
2
+ class Base
3
+ def self.enqueue(sqs_queue, method, *args)
4
+ tmail_obj = self.send("create_#{method}".to_sym, *args)
5
+ deliver_now = false
6
+
7
+ if sqs_queue.is_a? RightAws::SqsGen2::Queue
8
+ yaml_obj = YAML::dump(tmail_obj)
9
+ if yaml_obj.size < 8192
10
+ sqs_queue.push yaml_obj
11
+ RAILS_DEFAULT_LOGGER.info "[MAIL ENQUEUED] FROM: #{tmail_obj.from} TO: #{tmail_obj.to.join(',')} SUBJECT: #{tmail_obj.subject}"
12
+ else
13
+ deliver_now = true
14
+ end
15
+ else
16
+ deliver_now = true
17
+ end
18
+
19
+ if deliver_now
20
+ self.deliver(tmail_obj)
21
+ RAILS_DEFAULT_LOGGER.warn "[MAIL NOT ENQUEUED] FROM: #{tmail_obj.from} TO: #{tmail_obj.to.join(',')} SUBJECT: #{tmail_obj.subject} SIZE:#{defined?(yaml_obj) ? yaml_obj.size : 'undetermined'}"
22
+ end
23
+
24
+ tmail_obj
25
+ end
26
+ end
27
+ end
28
+
29
+ module AwsSqs
30
+ module Mail
31
+ def self.process(sqs_queue)
32
+ exit_flag = false
33
+ until($exit)
34
+ success, failure = 0, 0
35
+
36
+ while(message = sqs_queue.receive)
37
+ if message.to_s == 'stop'
38
+ exit_flag = true
39
+ break
40
+ end
41
+
42
+ begin
43
+ tmail_obj = YAML::load(message.to_s)
44
+ mail_header =
45
+ ActionMailer::Base.deliver(tmail_obj)
46
+
47
+ RAILS_DEFAULT_LOGGER.info "[MAIL DELIVERED] FROM: #{tmail_obj.from} TO: #{tmail_obj.to.join(',')} SUBJECT: #{tmail_obj.subject}"
48
+ message.delete
49
+ rescue Exception => e
50
+ RAILS_DEFAULT_LOGGER.error "* [MAIL DELIVERY ERROR]"
51
+ RAILS_DEFAULT_LOGGER.error error.backtrace.inspect
52
+ end
53
+ break if $exit # leave if we're exiting
54
+ end
55
+
56
+ break if exit_flag
57
+
58
+ sleep(60)
59
+ end
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmantilla-aws_sqs_mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Mantilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-29 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Uses Amazon SQS to enqueue messages and then deliver them at a later time
17
+ email: daniel@celect.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.textile
24
+ files:
25
+ - MIT-LICENSE
26
+ - README.textile
27
+ - aws_sqs_mail.gemspec
28
+ - init.rb
29
+ - lib/aws_sqs_mail.rb
30
+ has_rdoc: false
31
+ homepage: http://github.com/dmantilla/aws_sqs_mail/tree/master
32
+ licenses:
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --main
36
+ - README.textile
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.3.5
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: Adds an enqueue method to ActionMailer::Base, this adds the message to Amazon SQS which can be delivered later
58
+ test_files: []
59
+