-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add aggregation blob storage base URL to templates * Call mailer worker if status is updated * Mailer and mailer worker (and specs) * Hound * Prefer deliver_now
- Loading branch information
Showing
9 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class AggregationCompletedMailer < ApplicationMailer | ||
layout false | ||
|
||
def aggregation_complete(agg) | ||
@user = User.find(agg.user_id) | ||
@email_to = @user.email | ||
base_url = ENV.fetch('AGGREGATION_STORAGE_BASE_URL', '') | ||
@zip_url = "#{base_url}/#{agg.uuid}/#{agg.uuid}.zip" | ||
@reductions_url = "#{base_url}/#{agg.uuid}/reductions.csv" | ||
|
||
@success = agg.completed? | ||
agg_status = @success ? 'was successful!' : 'failed' | ||
subject = "Your workflow aggregation #{agg_status}" | ||
|
||
mail(to: @email_to, subject: subject) | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
app/views/aggregation_completed_mailer/aggregation_complete.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Hello, | ||
|
||
Your workflow aggregation has finished processing. | ||
|
||
<% if @success %> | ||
The workflow was aggregated successfully. | ||
|
||
Click here to download a zip file containing the following: | ||
* Workflow classifications export | ||
* Workflow export | ||
* Extracts (one file per task) | ||
* Reductions | ||
|
||
<%= @zip_url %> | ||
|
||
Click here to download the reductions file by itself: | ||
|
||
<%= @reductions_url %> | ||
|
||
<% else %> | ||
The workflow failed to aggregate. Please contact us or try again. | ||
<% end %> | ||
|
||
If you have questions or if there were any issues with your aggregation, please email [email protected]. | ||
|
||
Cheers, | ||
The Zooniverse Team | ||
|
||
This is an automated email, please do not respond. | ||
|
||
To manage your Zooniverse email subscription preferences visit https://zooniverse.org/settings | ||
|
||
To unsubscribe to all Zooniverse messages please visit https://zooniverse.org/unsubscribe | ||
Please be aware that the above link will unsubscribe you from ALL Zooniverse emails. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class AggregationCompletedMailerWorker | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :data_high | ||
|
||
def perform(agg_id) | ||
aggregation = Aggregation.find(agg_id) | ||
AggregationCompletedMailer.aggregation_complete(aggregation).deliver_now | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe AggregationCompletedMailer, type: :mailer do | ||
let(:base_url) { 'https://example.com' } | ||
|
||
before do | ||
allow(ENV).to receive(:fetch).with('AGGREGATION_STORAGE_BASE_URL', '').and_return(base_url) | ||
end | ||
|
||
describe '#aggregation_complete' do | ||
let(:mail) { described_class.aggregation_complete(aggregation) } | ||
|
||
context 'with a successful aggregation' do | ||
let(:aggregation) { create(:aggregation, status: 'completed', uuid: 'asdf123asdf') } | ||
let(:uuid) { aggregation.uuid } | ||
|
||
it 'mails the user' do | ||
expect(mail.to).to match_array([aggregation.user.email]) | ||
end | ||
|
||
it 'includes the subject' do | ||
expect(mail.subject).to include('Your workflow aggregation was successful!') | ||
end | ||
|
||
it 'includes the zip file link' do | ||
expect(mail.body.encoded).to include("#{base_url}/#{uuid}/#{uuid}.zip") | ||
end | ||
|
||
it 'includes the reductions file link' do | ||
expect(mail.body.encoded).to include("#{base_url}/#{uuid}/reductions.csv") | ||
end | ||
|
||
it 'comes from [email protected]' do | ||
expect(mail.from).to include('[email protected]') | ||
end | ||
|
||
it 'has the success statement' do | ||
expect(mail.body.encoded).to include('The workflow was aggregated successfully.') | ||
end | ||
end | ||
|
||
context 'with a failed aggregation' do | ||
let(:aggregation) { create(:aggregation, status: 'failed') } | ||
|
||
it 'reports the failures statement' do | ||
expect(mail.body.encoded).to include('The workflow failed to aggregate.') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe AggregationCompletedMailerWorker do | ||
let(:aggregation) { create(:aggregation) } | ||
|
||
it 'delivers the mail' do | ||
expect { described_class.new.perform(aggregation.id) }.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
end | ||
|
||
context 'with missing attributes' do | ||
it 'is missing an aggregation and does not send' do | ||
expect { described_class.new.perform(nil) }.to not_change { ActionMailer::Base.deliveries.count } | ||
.and raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
end |