Permalink
Browse files

added time checking for email send

  • Loading branch information...
1 parent 614a96d commit 3b45288fef6634c15f8d86d863ab887efed5af7b @dshipper committed Feb 16, 2012
@@ -4,12 +4,18 @@ def index
@emails = Email.all
end
- def send_email
- Email.all.each do |email|
+ def drip
+ @emails = Email.where(:sent => false, :time => Faucet.today)
+ @sent = []
+ @emails.each do |email|
puts "Running: #{email.description}."
puts eval("::" + email.function)
+
+ @sent << email
+
+ email.sent = true
+ email.save
end
end
-
end
end
@@ -2,4 +2,8 @@ module Faucet
class Email < ActiveRecord::Base
validates_presence_of :email, :function, :time, :description
end
+
+ def self.today
+ (Time.now.midnight)..Time.now.end_of_day
+ end
end
@@ -0,0 +1,7 @@
+<ul>
+<% @sent.each do |email| %>
+ <li>Sent email to: <%= email.email %></li>
+ <%= email.description %>
+ <br>
+<% end %>
+</ul>
@@ -5,6 +5,6 @@
To: <%= email.email %><br>
Function: <%= email.function %><br>
Time: <%= email.time.to_s %><br>
- Sent: <%= email.sent.to_s %><br>
+ Sent: <%= email.sent.to_s %><br><br>
<% end %>
</ul>
View
@@ -1,4 +1,4 @@
Faucet::Engine.routes.draw do
- match 'send' => "emails#send_email"
+ match 'drip' => "emails#drip"
root :to => "emails#index"
end
@@ -2,5 +2,4 @@ class SimulateController < ApplicationController
def schedule
Faucet::Email.create!(:time => Time.now, :function => "UserMailer.one_week", :description => "One week reminder email", :email => "dshipper@gmail.com")
end
-
end

0 comments on commit 3b45288

Please sign in to comment.