module Spamotron class Client def process_mail(source) mail = TMail::Mail.parse(source) ::ActionMailer::Base.deliver(mail) end def process! while source = Spamotron.dequeue process_mail(source) end end def daemonize! pid_file = File.join(RAILS_ROOT, Spamotron.config[:pid_file]) if File.exists?(pid_file) puts 'pid already exists...start failed' return end interval = Spamotron.config[:interval] pid = fork do Signal.trap 'TERM' do File.delete(pid_file) end loop do process! sleep interval end end File.open(pid_file, 'w') { |file| file.write pid } Process.detach(pid) puts "Started spamotron daemon..." end end end