Created
June 28, 2011 15:07
-
-
Save brentkirby/1051339 to your computer and use it in GitHub Desktop.
Tiny resque mail worker setup that removes Rail's stupid dependencies so we can delay messages without the whole rails env. (used w mongo fork)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zlib' | |
class AnyMailer < ActionMailer::Base | |
def enqueue(method, *args) | |
message = self.send(method, *args) | |
Resque.enqueue(MailWorker, message: compressed_msg(message)) | |
end | |
# Could easily be changed to not use BSON | |
def compressed_msg(msg) | |
BSON::Binary.new(Zlib::Deflate.deflate(msg.to_yaml)) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zlib' | |
class MailWorker | |
class_attribute :smtp_config | |
def self.configure( options ) | |
options.merge!({ | |
:address => "smtp.sendgrid.net", | |
:enable_starttls_auto => true, | |
:port => 587, | |
:tls => true, | |
:authentication => 'plain' | |
}) | |
self.smtp_config = options | |
end | |
@queue = :mail | |
@delayed_jobs = true | |
def self.perform(options) | |
Mail.defaults do | |
delivery_method :smtp, MailWorker.smtp_config | |
end | |
comp = options['message'] | |
message = Mail::Message.from_yaml(Zlib::Inflate.inflate(comp.to_s)) | |
message.deliver! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment