Created
July 6, 2011 10:45
-
-
Save asok/1066986 to your computer and use it in GitHub Desktop.
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 'net/pop' | |
class Droms::ReplyMailerJob | |
def perform | |
logger = RAILS_DEFAULT_LOGGER | |
if (Droms::Configuration[:email_settings][:use_ssl]) | |
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) | |
port = 995 | |
else | |
port = nil | |
end | |
Net::POP3.start(Droms::Configuration[:email_settings][:host], port , Droms::Configuration[:email_settings][:user], Droms::Configuration[:email_settings][:password]) do |pop| | |
if pop.mails.empty? | |
logger.info "NO MAIL" | |
else | |
pop.mails.each do |email| | |
begin | |
ParserMailer.receive(email.pop) | |
email.delete | |
rescue Exception => e | |
logger.error "Error receiving email at " + Time.now.to_s + "::: " + e.message | |
end | |
end | |
end | |
end | |
end | |
def after(job) | |
Delayed::Job.enqueue(self.class.new, :run_at => 1.minute.from_now) | |
end | |
end | |
if ActiveRecord::Base.connection.tables.include?('delayed_jobs') | |
Delayed::Job.enqueue Droms::EventMailerJob.new | |
Delayed::Job.enqueue Droms::ReplyMailerJob.new | |
Delayed::Job.enqueue Droms::TimeoutEventStateJob.new | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment