added a rake task to email retention to admins

This commit is contained in:
Ilya Zhitomirskiy 2011-10-26 16:27:28 -07:00
parent 7e73865147
commit 53b27a7627
2 changed files with 32 additions and 5 deletions

View file

@ -6,17 +6,23 @@ class Notifier < ActionMailer::Base
def self.admin(string, recipients, opts = {}) def self.admin(string, recipients, opts = {})
mails = [] mails = []
recipients.each do |rec| recipients.each do |rec|
mail = single_admin(string, rec) mail = single_admin(string, rec, opts)
mails << mail mails << mail
end end
mails mails
end end
def single_admin(string, recipient) def single_admin(string, recipient, opts={})
@receiver = recipient @receiver = recipient
@string = string.html_safe @string = string.html_safe
mail(:to => @receiver.email,
:subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig[:pod_uri].host) default_opts = {:to => @receiver.email,
:from => AppConfig[:smtp_sender_address],
:subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig[:pod_uri].host}
default_opts.merge!(opts)
mail(default_opts)
end end
def started_sharing(recipient_id, sender_id) def started_sharing(recipient_id, sender_id)
@ -63,4 +69,4 @@ class Notifier < ActionMailer::Base
def with_recipient_locale(&block) def with_recipient_locale(&block)
I18n.with_locale(@notification.recipient.language, &block) I18n.with_locale(@notification.recipient.language, &block)
end end
end end

21
lib/tasks/stats.rake Normal file
View file

@ -0,0 +1,21 @@
require File.join(Rails.root, 'lib', 'statistics' )
namespace :stats do
desc 'Emails recent engagement statistics the admins'
task :email_retention => :environment do
return unless AppConfig[:admins].present?
admins = User.find_all_by_username( AppConfig[:admins])
require 'fastercsv'
string = FasterCSV.generate do |csv|
(0..32).each do |i|
csv << [i.to_s, Statistics.new.retention(i)]
end
end
Notifier.admin(string, admins, {:subject => "retention numbers #{Time.now.to_s}"})
end
end