VRFS-1698 removed sendgrid email error handling

This commit is contained in:
Jonathan Kolyer 2014-05-31 09:03:18 +00:00
parent 2009b9715f
commit 30037bc967
5 changed files with 0 additions and 130 deletions

View File

@ -1,29 +0,0 @@
ActiveAdmin.register JamRuby::EmailError, :as => 'Email Errors' do
menu :label => 'Email Errors', :parent => 'Email'
config.batch_actions = false
config.filters = false
config.clear_action_items!
index do
column 'User' do |eerr|
eerr.user ? link_to(eerr.user.name, admin_user_path(eerr.user_id)) : 'N/A'
end
column 'Error Type' do |eerr| eerr.error_type end
column 'Email Address' do |eerr| eerr.email_address end
column 'Status' do |eerr| eerr.status end
column 'Reason' do |eerr| eerr.reason end
column 'Email Date' do |eerr| eerr.email_date end
end
controller do
def scoped_collection
@eerrors ||= end_of_association_chain
.includes([:user])
.order('email_date DESC')
end
end
end

View File

@ -145,7 +145,6 @@ require "jam_ruby/models/email_batch_periodic"
require "jam_ruby/models/email_batch_new_musician"
require "jam_ruby/models/email_batch_progression"
require "jam_ruby/models/email_batch_set"
require "jam_ruby/models/email_error"
require "jam_ruby/app/mailers/async_mailer"
require "jam_ruby/app/mailers/batch_mailer"
require "jam_ruby/app/mailers/progress_mailer"

View File

@ -1,80 +0,0 @@
module JamRuby
class EmailError < ActiveRecord::Base
self.table_name = "email_errors"
belongs_to :user, :class_name => 'JamRuby::User'
default_scope :order => 'email_date DESC'
ERR_BOUNCE = :bounce
ERR_INVALID = :invalid
SENDGRID_UNAME = 'jamkazam'
SENDGRID_PASSWD = 'jamjamblueberryjam'
def self.sendgrid_url(resource, action='get', params='')
start_date, end_date = self.date_range
"https://api.sendgrid.com/api/#{resource}.#{action}.json?api_user=#{EmailError::SENDGRID_UNAME}&api_key=#{EmailError::SENDGRID_PASSWD}&date=1&start_date=#{start_date.strftime('%Y-%m-%d')}&end_date=#{end_date.strftime('%Y-%m-%d')}&#{params}"
end
def self.date_range
tt = Time.now
if eerr = self.first
return [eerr.email_date, tt]
end
[tt - 1.year, tt]
end
def self.did_capture?(email_addy)
self.where(:email_address => email_addy).limit(1).first.present?
end
def self.bounce_errors
uu = self.sendgrid_url('bounces')
response = RestClient.get(uu)
if 200 == response.code
return JSON.parse(response.body).collect do |jj|
next if self.did_capture?(jj['email'])
ee = EmailError.new
ee.error_type = 'bounces'
ee.email_address = jj['email']
ee.user_id = User.where(:email => ee.email_address).pluck(:id).first
ee.status = jj['status']
ee.email_date = jj['created']
ee.reason = jj['reason']
ee.save!
# RestClient.delete(self.sendgrid_url('bounces', 'delete', "email=#{ee.email_address}"))
ee
end
end
end
def self.invalid_errors
uu = self.sendgrid_url('invalidemails')
response = RestClient.get(uu)
if 200 == response.code
return JSON.parse(response.body).collect do |jj|
next if self.did_capture?(jj['email'])
ee = EmailError.new
ee.error_type = 'invalidemails'
ee.email_address = jj['email']
ee.user_id = User.where(:email => ee.email_address).pluck(:id).first
ee.email_date = jj['created']
ee.reason = jj['reason']
ee.save!
uu =
# RestClient.delete(self.sendgrid_url('invalidemails', 'delete', "email=#{ee.email_address}"))
ee
end
end
end
def self.capture_errors
EmailError.bounce_errors
EmailError.invalid_errors
end
end
end

View File

@ -1,15 +0,0 @@
module JamRuby
class EmailErrorCollector
extend Resque::Plugins::LonelyJob
@queue = :email_error_collector
@@log = Logging.logger[EmailErrorCollector]
def self.perform
@@log.debug("waking up")
EmailError.capture_errors
@@log.debug("done")
end
end
end

View File

@ -19,11 +19,6 @@ CleanupFacebookSignup:
class: "JamRuby::CleanupFacebookSignup"
description: "Deletes facebook_signups that are old"
EmailErrorCollector:
cron: "0 14 * * *"
class: "JamRuby::EmailErrorCollector"
description: "Collects sendgrid email errors"
UserProgressEmailer:
cron: "30 21 * * *"
class: "JamRuby::UserProgressEmailer"