Skip to content

Instantly share code, notes, and snippets.

@qrush
Created November 25, 2008 07:51
Show Gist options
  • Save qrush/28847 to your computer and use it in GitHub Desktop.
Save qrush/28847 to your computer and use it in GitHub Desktop.
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
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