added a rake task to email retention to admins
This commit is contained in:
parent
7e73865147
commit
53b27a7627
2 changed files with 32 additions and 5 deletions
|
|
@ -6,17 +6,23 @@ class Notifier < ActionMailer::Base
|
|||
def self.admin(string, recipients, opts = {})
|
||||
mails = []
|
||||
recipients.each do |rec|
|
||||
mail = single_admin(string, rec)
|
||||
mail = single_admin(string, rec, opts)
|
||||
mails << mail
|
||||
end
|
||||
mails
|
||||
end
|
||||
|
||||
def single_admin(string, recipient)
|
||||
def single_admin(string, recipient, opts={})
|
||||
@receiver = recipient
|
||||
@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
|
||||
|
||||
def started_sharing(recipient_id, sender_id)
|
||||
|
|
@ -63,4 +69,4 @@ class Notifier < ActionMailer::Base
|
|||
def with_recipient_locale(&block)
|
||||
I18n.with_locale(@notification.recipient.language, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
21
lib/tasks/stats.rake
Normal file
21
lib/tasks/stats.rake
Normal 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
|
||||
Loading…
Reference in a new issue