Skip to content

Commit

Permalink
finish daily report job (#392)
Browse files Browse the repository at this point in the history
* add govdelivery server to app yml

* use govdelivery server in staging email method

* use govdelivery server in config helper

* fix server name

* add year to date report to scheduler

* perform doesnt require argument

* fix statds for spring, add govdelivery server to figaro

* add govdelivery server to travis

* add va stakeholders

* lint

* rename report mailer

* rename constants
  • Loading branch information
lihanli authored Nov 3, 2016
1 parent 3af9a6a commit 690de5d
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 63 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ before_script:
- export NCA_MAPSERVER_URL='https://services3.arcgis.com/aqgBd3l68G8hEFFE/ArcGIS/rest/services/NCA_Facilities/FeatureServer/0'
- export VBA_MAPSERVER_URL='https://services3.arcgis.com/aqgBd3l68G8hEFFE/ArcGIS/rest/services/VBA_Facilities/FeatureServer/0'
- export MOCK_MVI_SERVICE=false
- export GOV_DELIVERY_SERVER='stage-tms.govdelivery.com'
script:
- bundle exec rake db:create db:schema:load ci
bundler_args: "--without development"
Expand Down
32 changes: 0 additions & 32 deletions app/mailers/report_mailer.rb

This file was deleted.

62 changes: 62 additions & 0 deletions app/mailers/year_to_date_report_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true
class YearToDateReportMailer < ApplicationMailer
REPORT_TEXT = 'Year to date report'

VA_STAKEHOLDERS = {
to: %w(
Christopher.Marino2@va.gov
224A.VBACO@va.gov
rodney.alexander@va.gov
URSULA.BRITT@va.gov
Carolyn.McCollam@va.gov
shay.norton@va.gov
Christina.DiTucci@va.gov
),
cc: %w(
robert.orifici@va.gov
Erin.Haskins@va.gov
Shante.Kinzie@va.gov
Brandye.Terrell@va.gov
michele.mendola@va.gov
Schnell.Carraway@va.gov
Danita.Johnson@va.gov
jude.lopez1@va.gov
Steven.Wayland@va.gov
)
}.freeze

def build(report_file)
s3_resource = new_s3_resource
obj = s3_resource.bucket(s3_bucket).object("#{SecureRandom.uuid}.csv")
obj.upload_file(report_file, content_type: 'text/csv')
url = obj.presigned_url(:get, expires_in: 1.week)

opt = {}
if FeatureFlipper.staging_email?
opt[:to] = 'lihan@adhocteam.us'
else
opt = VA_STAKEHOLDERS.clone
end

mail(
opt.merge(
subject: REPORT_TEXT,
body: "#{REPORT_TEXT} (link expires in one week)<br>#{url}"
)
)
end

private

def s3_bucket
ENV['REPORTS_AWS_S3_BUCKET']
end

def new_s3_resource
Aws::S3::Resource.new(
region: ENV['REPORTS_AWS_S3_REGION'],
access_key_id: ENV['REPORTS_AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['REPORTS_AWS_SECRET_ACCESS_KEY']
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def create_csv_array
csv_array
end

def perform(date)
@date = date
def perform
@date = Time.zone.today
folder = 'tmp/daily_reports'
FileUtils.mkdir_p(folder)
filename = "#{folder}/#{@date}.csv"
Expand All @@ -74,9 +74,7 @@ def perform(date)
end

return unless FeatureFlipper.send_email?
ReportMailer.year_to_date_report_email(filename).deliver_now

# TODO: add rake task to cron
YearToDateReportMailer.build(filename).deliver_now
end
end
end
2 changes: 1 addition & 1 deletion config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MVI_URL: 'http://see.project.readme.for.instructions.org'
MVI_CLIENT_CERT_PATH: '/fake/client/cert/path'
MVI_CLIENT_KEY_PATH: '/fake/client/key/path'
MOCK_MVI_SERVICE: 'true'
STAGING_EMAIL: 'true'
GOV_DELIVERY_SERVER: stage-tms.govdelivery.com

# For CORS requests; separate multiple origins with a comma
WEB_ORIGIN: 'http://localhost:3000,http://localhost:3001'
3 changes: 2 additions & 1 deletion config/initializers/figaro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'EVSS_S3_UPLOADS',
'VHA_MAPSERVER_URL',
'NCA_MAPSERVER_URL',
'VBA_MAPSERVER_URL'
'VBA_MAPSERVER_URL',
'GOV_DELIVERY_SERVER'
)

if Rails.env.production?
Expand Down
4 changes: 4 additions & 0 deletions config/sidekiq_scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ CreateDailySpoolFiles:
class: EducationForm::CreateDailySpoolFiles
description: "Generate a daily set of spool files and transmit them over SFTP to a backend system"

EducationForm::CreateDailyYearToDateReport:
cron: "0 4 * * * America/New_York"
description: "Send the daily report to VA stakeholders about Education Benefits submissions"

DeleteOldApplications:
cron: "0 0 * * * America/New_York"
class: EducationForm::DeleteOldApplications
Expand Down
2 changes: 1 addition & 1 deletion lib/config_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setup_action_mailer(config)
config.action_mailer.delivery_method = :govdelivery_tms
config.action_mailer.govdelivery_tms_settings = {
auth_token: ENV['GOV_DELIVERY_TOKEN'],
api_root: "https://#{FeatureFlipper.staging_email? ? 'stage-' : ''}tms.govdelivery.com"
api_root: "https://#{ENV['GOV_DELIVERY_SERVER']}"
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/feature_flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def self.send_email?
end

def self.staging_email?
ENV['STAGING_EMAIL'] == 'true'
ENV['GOV_DELIVERY_SERVER'].include?('stage')
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
create_daily_year_to_date_report = described_class.new

stub_reports_s3(filename) do
create_daily_year_to_date_report.perform(date)
create_daily_year_to_date_report.perform
end

create_daily_year_to_date_report
Expand Down
21 changes: 0 additions & 21 deletions spec/mailers/report_mailer_spec.rb

This file was deleted.

52 changes: 52 additions & 0 deletions spec/mailers/year_to_date_report_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe YearToDateReportMailer, type: [:mailer, :aws_helpers] do
describe '#year_to_date_report_email' do
let(:filename) { 'foo' }
let(:mail) { described_class.build(filename).deliver_now }
subject do
stub_reports_s3(filename) do
mail
end
end

it 'should send the right email' do
subject
text = described_class::REPORT_TEXT
expect(mail.body.encoded).to eq("#{text} (link expires in one week)<br>#{subject}")
expect(mail.subject).to eq(text)
end

context 'when not sending staging emails' do
before do
expect(FeatureFlipper).to receive(:staging_email?).once.and_return(false)
end

it 'should email the va stakeholders' do
subject
expect(mail.to).to eq(
['Christopher.Marino2@va.gov',
'224A.VBACO@va.gov',
'rodney.alexander@va.gov',
'URSULA.BRITT@va.gov',
'Carolyn.McCollam@va.gov',
'shay.norton@va.gov',
'Christina.DiTucci@va.gov']
)

expect(mail.cc).to eq(
['robert.orifici@va.gov',
'Erin.Haskins@va.gov',
'Shante.Kinzie@va.gov',
'Brandye.Terrell@va.gov',
'michele.mendola@va.gov',
'Schnell.Carraway@va.gov',
'Danita.Johnson@va.gov',
'jude.lopez1@va.gov',
'Steven.Wayland@va.gov']
)
end
end
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'statsd-instrument'
require 'statsd/instrument/matchers'
require 'rspec/rails'
require 'webmock/rspec'
require 'support/factory_girl'
Expand Down

0 comments on commit 690de5d

Please sign in to comment.