[FAILING] Seeing what happens when I take Delayed::Job out...

pull/968/head
Rick Carlino 2018-08-17 08:10:32 -05:00
parent 460462688b
commit 35980eb718
3 changed files with 32 additions and 9 deletions

View File

@ -2,6 +2,16 @@ class LogDeliveryMailer < ApplicationMailer
WHOAH = "Device %s is sending too many emails!!! (> 20 / hr)"
SUBJECT = "🌱 New message from %s!"
def log_digest(device)
Log.transaction do
maybe_crash_if_too_many_logs(device)
unsent = device.unsent_routine_emails
send_a_digest(device, unsent) if unsent.any?
end
end
private
def timestamp(time, zone)
time.in_time_zone(zone).strftime("%F %I:%M %p")
end
@ -25,11 +35,4 @@ class LogDeliveryMailer < ApplicationMailer
unsent.update_all(sent_at: Time.now)
end
def log_digest(device)
Log.transaction do
maybe_crash_if_too_many_logs(device)
unsent = device.unsent_routine_emails
send_a_digest(device, unsent) if unsent.any?
end
end
end

View File

@ -22,8 +22,9 @@ module LogDeliveryStuff
# TODO: Why must I explicitly pass `mailer_klass`? Somethings not right with
# mocks.
def send_routine_emails(log, device, mailer_klass = LogDeliveryMailer)
return unless (log.channels || []).include?("email")
mailer_klass.log_digest(device).deliver_later(digest_wait_time)
puts "THIS IS TEMPORARILY STUBBED OUT!"
# return unless (log.channels || []).include?("email")
# mailer_klass.log_digest(device).deliver_later(digest_wait_time)
end
def send_fatal_emails(log, device)

View File

@ -7,6 +7,25 @@ def same_thing
end
namespace :api do
desc "Just testing things out"
task log_digest: :environment do
puts "=== Looking for digests..."
Log
.where(sent_at: nil, created_at: 1.day.ago...Time.now)
.where(Log::IS_EMAIL_ISH)
.where
.not(Log::IS_FATAL_EMAIL)
.pluck(:device_id)
.uniq
.tap {|ids| puts "=== Found #{ids.count} digests..."}
.map do |id|
device = Device.find(id)
puts "=== Sending email digest to #{device.name}: #{device.id}"
LogDeliveryMailer.log_digest(device)
end
puts "=== Done."
end
desc "Run Webpack and Rails"
task start: :environment do
sh "PORT=3000 bundle exec foreman start --procfile=Procfile.dev"