diff --git a/admin/app/admin/email_batch.rb b/admin/app/admin/email_batch.rb index e5743eeb8..e31ec5cce 100644 --- a/admin/app/admin/email_batch.rb +++ b/admin/app/admin/email_batch.rb @@ -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 diff --git a/admin/app/admin/email_error_batch.rb b/admin/app/admin/email_error_batch.rb deleted file mode 100644 index 9c4ce9280..000000000 --- a/admin/app/admin/email_error_batch.rb +++ /dev/null @@ -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 diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 64544ad7d..dec2cde7a 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -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" diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 17f238090..19a0ea794 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -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) diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_dl_notrun.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_dl_notrun.text.erb index 110ddcfac..c447c34fb 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_dl_notrun.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_dl_notrun.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_notdl.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_notdl.text.erb index cb5d3dbaa..4ec636c7b 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_notdl.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_notdl.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_run_notgear.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_run_notgear.text.erb index 190ae73ae..b635ede90 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_run_notgear.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/client_run_notgear.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/gear_notsess.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/gear_notsess.text.erb index 74978f1e3..d027cf178 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/gear_notsess.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/gear_notsess.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notconnect.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notconnect.text.erb index 24f5360b3..370823a10 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notconnect.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notconnect.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notinvite.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notinvite.text.erb index 05d50f493..372ab08da 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notinvite.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notinvite.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notlike.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notlike.text.erb index 86ea83312..9dddb6ca6 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notlike.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/reg_notlike.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notgood.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notgood.text.erb index a0519e8f3..28030d0dd 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notgood.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notgood.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notrecord.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notrecord.text.erb index 614cd98fc..301bef449 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notrecord.text.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/progress_mailer/sess_notrecord.text.erb @@ -1,4 +1,4 @@ -<% provide(:title, @title) %> +<%= @title %> Hello <%= EmailBatchProgression::VAR_FIRST_NAME %> -- diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index a816ac422..8389c56c5 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/email_batch_set.rb b/ruby/lib/jam_ruby/models/email_batch_set.rb index cdb963ad4..142d03169 100644 --- a/ruby/lib/jam_ruby/models/email_batch_set.rb +++ b/ruby/lib/jam_ruby/models/email_batch_set.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/email_error.rb b/ruby/lib/jam_ruby/models/email_error.rb deleted file mode 100644 index fe693b849..000000000 --- a/ruby/lib/jam_ruby/models/email_error.rb +++ /dev/null @@ -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 diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index acb82fdc0..88000f782 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -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? diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 59b34c405..44712bbb7 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -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 diff --git a/ruby/lib/jam_ruby/resque/batch_email_job.rb b/ruby/lib/jam_ruby/resque/batch_email_job.rb new file mode 100644 index 000000000..6d82d420e --- /dev/null +++ b/ruby/lib/jam_ruby/resque/batch_email_job.rb @@ -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 diff --git a/ruby/lib/jam_ruby/resque/scheduled/email_error_collector.rb b/ruby/lib/jam_ruby/resque/scheduled/email_error_collector.rb deleted file mode 100644 index 0c6fc9397..000000000 --- a/ruby/lib/jam_ruby/resque/scheduled/email_error_collector.rb +++ /dev/null @@ -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 diff --git a/web/app/assets/javascripts/findMusician.js b/web/app/assets/javascripts/findMusician.js index 38bf79976..f29dc9afb 100644 --- a/web/app/assets/javascripts/findMusician.js +++ b/web/app/assets/javascripts/findMusician.js @@ -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; diff --git a/web/app/assets/stylesheets/client/band.css.scss b/web/app/assets/stylesheets/client/band.css.scss index 25f45e9a2..4da4130d3 100644 --- a/web/app/assets/stylesheets/client/band.css.scss +++ b/web/app/assets/stylesheets/client/band.css.scss @@ -162,11 +162,11 @@ } } .lcol { - width: 148px; + width: 200px; } .whitespace { // equal to lcol width. - padding-left: 148px; + padding-left: 200px; } .instruments { width:128px; diff --git a/web/app/assets/stylesheets/client/profile.css.scss b/web/app/assets/stylesheets/client/profile.css.scss index f1c207801..746f783e3 100644 --- a/web/app/assets/stylesheets/client/profile.css.scss +++ b/web/app/assets/stylesheets/client/profile.css.scss @@ -231,11 +231,11 @@ } } .lcol { - width: 148px; + width: 200px; } .whitespace { // equal to lcol width. - padding-left: 148px; + padding-left: 200px; } .instruments { width:128px; diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index 468371a79..3d57aeffc 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -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 diff --git a/web/app/views/clients/_musicians.html.erb b/web/app/views/clients/_musicians.html.erb index 599710a6c..47da7d626 100644 --- a/web/app/views/clients/_musicians.html.erb +++ b/web/app/views/clients/_musicians.html.erb @@ -32,12 +32,12 @@