Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
da4fc4bcbd
|
|
@ -115,7 +115,7 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do
|
|||
end
|
||||
|
||||
member_action :batch_send, :method => :get do
|
||||
resource.deliver_batch
|
||||
resource.deliver_batch_async
|
||||
redirect_to admin_batch_email_path(resource.id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -43,6 +43,7 @@ require "jam_ruby/resque/scheduled/icecast_source_check"
|
|||
require "jam_ruby/resque/scheduled/cleanup_facebook_signup"
|
||||
require "jam_ruby/resque/scheduled/user_progress_emailer"
|
||||
require "jam_ruby/resque/google_analytics_event"
|
||||
require "jam_ruby/resque/batch_email_job"
|
||||
require "jam_ruby/mq_router"
|
||||
require "jam_ruby/base_manager"
|
||||
require "jam_ruby/connection_manager"
|
||||
|
|
@ -144,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"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
module JamRuby
|
||||
class BatchMailer < JamRuby::AsyncMailer
|
||||
class BatchMailer < ActionMailer::Base
|
||||
include SendGrid
|
||||
layout "user_mailer"
|
||||
|
||||
sendgrid_category :use_subject_lines
|
||||
|
|
@ -23,10 +24,10 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def send_batch_email(batch_id, user_ids)
|
||||
users = User.find_all_by_id(user_ids)
|
||||
def send_batch_email(batch_id, user_id)
|
||||
user = User.find_by_id(user_id)
|
||||
batch = EmailBatch.find(batch_id)
|
||||
self._send_batch(batch, users)
|
||||
self._send_batch(batch, [user])
|
||||
end
|
||||
|
||||
def send_batch_email_test(batch_id)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, @title) %>
|
||||
<%= @title %>
|
||||
|
||||
Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> --
|
||||
|
||||
|
|
|
|||
|
|
@ -79,12 +79,12 @@ FOO
|
|||
end
|
||||
|
||||
def deliver_batch_sets!
|
||||
User.email_opt_in.find_in_batches(batch_size: BATCH_SIZE) do |users|
|
||||
self.email_batch_sets << (bset = EmailBatchSet.load_set(self, users.map(&:id)))
|
||||
User.email_opt_in.find_each do |user|
|
||||
bset = EmailBatchSet.sent_email(self, user.id)
|
||||
if 'test' == Rails.env
|
||||
BatchMailer.send_batch_email(self.id, bset.user_ids).deliver!
|
||||
BatchMailer.send_batch_email(self.id, bset.user_id).deliver!
|
||||
else
|
||||
BatchMailer.send_batch_email(self.id, bset.user_ids).deliver
|
||||
BatchMailer.send_batch_email(self.id, bset.user_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -94,6 +94,10 @@ FOO
|
|||
self.deliver_batch_sets!
|
||||
end
|
||||
|
||||
def deliver_batch_async
|
||||
BatchEmailJob.enqueue(self.id)
|
||||
end
|
||||
|
||||
def test_count
|
||||
self.test_emails.split(',').count
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,12 +5,22 @@ module JamRuby
|
|||
belongs_to :email_batch, :class_name => 'JamRuby::EmailBatch'
|
||||
belongs_to :user, :class_name => 'JamRuby::User'
|
||||
|
||||
def self.load_set(batch, user_ids)
|
||||
# def self.load_set(batch, user_ids)
|
||||
# bset = self.new
|
||||
# bset.email_batch_id = batch.id
|
||||
# bset.user_ids = user_ids.join(',')
|
||||
# bset.started_at = Time.now
|
||||
# bset.batch_count = user_ids.size
|
||||
# bset.save!
|
||||
# bset
|
||||
# end
|
||||
|
||||
def self.sent_email(batch, user_id)
|
||||
bset = self.new
|
||||
bset.email_batch_id = batch.id
|
||||
bset.user_ids = user_ids.join(',')
|
||||
bset.user_id = user_id
|
||||
bset.started_at = Time.now
|
||||
bset.batch_count = user_ids.size
|
||||
bset.batch_count = 1
|
||||
bset.save!
|
||||
bset
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -179,7 +179,7 @@ module JamRuby
|
|||
unless locidispid.nil?
|
||||
# score_join of left allows for null scores, whereas score_join of inner requires a score however good or bad
|
||||
# this is ANY_SCORE:
|
||||
score_join = 'left' # or 'inner'
|
||||
score_join = 'left outer' # or 'inner'
|
||||
score_min = nil
|
||||
score_max = nil
|
||||
case score_limit
|
||||
|
|
@ -214,7 +214,7 @@ module JamRuby
|
|||
end
|
||||
|
||||
rel = rel.joins("#{score_join} join scores on scores.alocidispid = users.last_jam_locidispid")
|
||||
.where(['scores.blocidispid = ?', locidispid])
|
||||
.where(['(scores.blocidispid = ? or scores.blocidispid is null)', locidispid])
|
||||
|
||||
rel = rel.where(['scores.score > ?', score_min]) unless score_min.nil?
|
||||
rel = rel.where(['scores.score <= ?', score_max]) unless score_max.nil?
|
||||
|
|
|
|||
|
|
@ -292,7 +292,8 @@ module JamRuby
|
|||
|
||||
def joined_score
|
||||
nil unless has_attribute?(:score)
|
||||
read_attribute(:score).to_i
|
||||
a = read_attribute(:score)
|
||||
a.nil? ? nil : a.to_i
|
||||
end
|
||||
|
||||
# mods comes back as text; so give ourselves a parsed version
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
require 'resque'
|
||||
require 'resque-lonely_job'
|
||||
|
||||
module JamRuby
|
||||
class BatchEmailJob
|
||||
extend Resque::Plugins::LonelyJob
|
||||
|
||||
@@log = Logging.logger[BatchEmailJob]
|
||||
|
||||
@queue = :batch_emails
|
||||
|
||||
def self.perform(batch_id)
|
||||
if ebatch = EmailBatch.find_by_id(batch_id)
|
||||
ebatch.deliver_batch
|
||||
end
|
||||
end
|
||||
|
||||
def self.enqueue(batch_id)
|
||||
begin
|
||||
Resque.enqueue(self, batch_id)
|
||||
true
|
||||
rescue
|
||||
# implies redis is down. but since there is no retry logic with this, we should at least log a warn in case we've configured something wrong
|
||||
@@log.warn("unable to enqueue")
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
@ -78,6 +78,30 @@
|
|||
}
|
||||
}
|
||||
|
||||
function score_to_text(score) {
|
||||
// these are raw scores as reported by client (round trip times)
|
||||
if (score == null) return "n/a";
|
||||
return Math.round(score / 2) + " ms";
|
||||
}
|
||||
|
||||
function score_to_color(score) {
|
||||
// these are raw scores as reported by client (round trip times)
|
||||
if (score == null) return "purple";
|
||||
if (0 < score && score <= 40) return "green";
|
||||
if (40 < score && score <= 80) return "yellow";
|
||||
if (80 < score && score <= 120) return "red";
|
||||
return "blue";
|
||||
}
|
||||
|
||||
function score_to_color_alt(score) {
|
||||
// these are raw scores as reported by client (round trip times)
|
||||
if (score == null) return "missing";
|
||||
if (0 < score && score <= 40) return "good";
|
||||
if (40 < score && score <= 80) return "moderate";
|
||||
if (80 < score && score <= 120) return "poor";
|
||||
return "unacceptable";
|
||||
}
|
||||
|
||||
function renderMusicians() {
|
||||
var ii, len;
|
||||
var mTemplate = $('#template-find-musician-row').html();
|
||||
|
|
@ -108,7 +132,7 @@
|
|||
user_id: aFollow.user_id,
|
||||
musician_name: aFollow.name,
|
||||
profile_url: '/client#/profile/' + aFollow.user_id,
|
||||
avatar_url: context.JK.resolveAvatarUrl(aFollow.photo_url),
|
||||
avatar_url: context.JK.resolveAvatarUrl(aFollow.photo_url)
|
||||
};
|
||||
follows += context.JK.fillTemplate(fTemplate, followVals);
|
||||
if (2 == jj) break;
|
||||
|
|
@ -125,6 +149,7 @@
|
|||
};
|
||||
var musician_actions = context.JK.fillTemplate(aTemplate, actionVals);
|
||||
|
||||
var joined_score = musician['joined_score']
|
||||
mVals = {
|
||||
avatar_url: context.JK.resolveAvatarUrl(musician.photo_url),
|
||||
profile_url: "/client#/profile/" + musician.id,
|
||||
|
|
@ -138,7 +163,10 @@
|
|||
session_count: musician['session_count'],
|
||||
musician_id: musician['id'],
|
||||
musician_follow_template: follows,
|
||||
musician_action_template: musician_actions
|
||||
musician_action_template: musician_actions,
|
||||
musician_one_way_score: score_to_text(joined_score),
|
||||
musician_score_color: score_to_color(joined_score),
|
||||
musician_score_color_alt: score_to_color_alt(joined_score)
|
||||
};
|
||||
var musician_row = context.JK.fillTemplate(mTemplate, mVals);
|
||||
renderings += musician_row;
|
||||
|
|
|
|||
|
|
@ -162,11 +162,11 @@
|
|||
}
|
||||
}
|
||||
.lcol {
|
||||
width: 148px;
|
||||
width: 200px;
|
||||
}
|
||||
.whitespace {
|
||||
// equal to lcol width.
|
||||
padding-left: 148px;
|
||||
padding-left: 200px;
|
||||
}
|
||||
.instruments {
|
||||
width:128px;
|
||||
|
|
|
|||
|
|
@ -231,11 +231,11 @@
|
|||
}
|
||||
}
|
||||
.lcol {
|
||||
width: 148px;
|
||||
width: 200px;
|
||||
}
|
||||
.whitespace {
|
||||
// equal to lcol width.
|
||||
padding-left: 148px;
|
||||
padding-left: 200px;
|
||||
}
|
||||
.instruments {
|
||||
width:128px;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class ApiSearchController < ApiController
|
|||
conn = (clientid ? Connection.where(client_id: clientid, user_id: current_user.id).first : nil)
|
||||
# puts "================== query #{query.inspect}"
|
||||
@search = Search.musician_filter(query, current_user, conn)
|
||||
# puts "================== search #{@search.inspect}"
|
||||
else
|
||||
@search = Search.band_filter(query, current_user)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@
|
|||
</div>
|
||||
<!-- todo scott vfrs-1455 i need a template tutorial to define the three variables that substitute here:
|
||||
score:
|
||||
one_way_score is joined_score / 2;
|
||||
score_color is green, yellow, red, blue, or purple (depending upon value of joined_score)
|
||||
score_color_alt is good, moderate, poor, unacceptable,or missing
|
||||
musician_one_way_score is joined_score / 2;
|
||||
musician_score_color is green, yellow, red, blue, or purple (depending upon value of joined_score)
|
||||
musician_score_color_alt is good, moderate, poor, unacceptable,or missing
|
||||
-->
|
||||
<!-- <div class="left" style="***help***">
|
||||
{one_way_score} ms <img src="../assets/content/icon_{score_color}_score.png" alt="{score_color_alt}" width="12" height="12" align="absmiddle"/>
|
||||
{musician_one_way_score} <img src="../assets/content/icon_{musician_score_color}_score.png" alt="{musician_score_color_alt}" width="12" height="12" align="absmiddle"/>
|
||||
</div> -->
|
||||
<div class="right musician-following" style="width: 120px;">
|
||||
<div class="bold">FOLLOWING:</div>
|
||||
|
|
@ -58,10 +58,11 @@
|
|||
</div>
|
||||
<div class="button-row" data-hint="button-row">
|
||||
<div class="lcol stats left">
|
||||
{friend_count} <img src="../assets/content/icon_friend.png" width="14" height="12" align="absmiddle" style="margin-right:4px;"/>
|
||||
{follow_count} <img src="../assets/content/icon_followers.png" width="22" height="12" align="absmiddle" style="margin-right:4px;"/>
|
||||
{recording_count} <img src="../assets/content/icon_recordings.png" width="12" height="13" align="absmiddle" style="margin-right:4px;"/>
|
||||
{session_count} <img src="../assets/content/icon_session_tiny.png" width="12" height="12" align="absmiddle" />
|
||||
{friend_count} <img src="../assets/content/icon_friend.png" alt="friends" width="14" height="12" align="absmiddle" style="margin-right:4px;"/>
|
||||
{follow_count} <img src="../assets/content/icon_followers.png" alt="follows" width="22" height="12" align="absmiddle" style="margin-right:4px;"/>
|
||||
{recording_count} <img src="../assets/content/icon_recordings.png" alt="recordings" width="12" height="13" align="absmiddle" style="margin-right:4px;"/>
|
||||
{session_count} <img src="../assets/content/icon_session_tiny.png" alt="sessions" width="12" height="12" align="absmiddle" style="margin-right:4px;"/>
|
||||
{musician_one_way_score} <img src="../assets/content/icon_{musician_score_color}_score.png" alt="{musician_score_color_alt} score" width="12" height="12" align="absmiddle" style="margin-right:4px;"/>
|
||||
</div>
|
||||
<div class="result-list-button-wrapper" data-musician-id={musician_id}>
|
||||
{musician_action_template}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue