Created
November 25, 2008 07:51
-
-
Save qrush/28847 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class StatusReminder | |
class << self | |
def send_reminders | |
offset = 0 | |
jump = 100 | |
while( users = User.eligible_for_status_reminder(offset, jump) && !users.empty? ) | |
users.each do |user| | |
logger.info("StatusReminder: Reminding #{user}") | |
Mailer.deliver_status_reminder(user) | |
user.update_attribute(:last_status_reminder_sent_at, Time.now) | |
end | |
offset += jump | |
end | |
logger.info("StatusReminder: No users to remind.") unless users | |
end | |
end | |
end |
This file contains hidden or 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
named_scope :eligible_for_status_reminder, lambda { |offset, limit| | |
{:conditions => [" | |
status_reminder = ? AND | |
last_status_created_at <= ? AND | |
(last_status_reminder_sent_at <= ? OR last_status_reminder_sent_at IS NULL)", | |
true, 5.days.ago, 5.days.ago], | |
:offset => offset, | |
:limit => limit} | |
} | |
def to_s | |
username | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment