Skip to content

Commit

Permalink
Merge pull request #413 from alphagov/revert-411-switch-global-export…
Browse files Browse the repository at this point in the history
…-to-s3

Revert "Upload exported CSV file to S3 rather than attaching it"
  • Loading branch information
benjamineskola committed Feb 5, 2020
2 parents 72726af + 1970ffe commit 4d333ec
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 88 deletions.
7 changes: 4 additions & 3 deletions app/mailers/global_export_notification.rb
@@ -1,9 +1,10 @@
class GlobalExportNotification < ApplicationMailer
def notification_email(notification_email, url)
@url = url
def notification_email(notification_email, filename, csv_contents)
attachments[filename] = csv_contents

mail(
to: notification_email,
subject: "[GOV.UK Feedback Explorer] Your global export is ready",
subject: "[GOV.UK Feedback Explorer] Your global export is attached",
)
end
end
@@ -1,7 +1,5 @@
Hi,

Use the link below to download your CSV file from Feedback Explorer.

<%= @url %>
Your CSV file is attached.

- Feedex
20 changes: 17 additions & 3 deletions app/workers/generate_feedback_csv_worker.rb
@@ -1,5 +1,3 @@
require "s3_file_uploader"

class GenerateFeedbackCsvWorker
include Sidekiq::Worker

Expand All @@ -12,10 +10,26 @@ def perform(*args)
end

csv = feedback_export_request.generate_csv
S3FileUploader.save_file_to_s3(feedback_export_request.filename, csv)
self.class.save_file_to_s3(feedback_export_request.filename, csv)

feedback_export_request.touch(:generated_at)

ExportNotification.notification_email(feedback_export_request.notification_email, feedback_export_request.url).deliver_now
end

def self.save_file_to_s3(filename, csv)
connection = Fog::Storage.new(
provider: "AWS",
region: ENV["AWS_REGION"],
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
)

directory = connection.directories.get(ENV["AWS_S3_BUCKET_NAME"])

directory.files.create(
key: filename,
body: csv,
)
end
end
6 changes: 1 addition & 5 deletions app/workers/generate_global_export_csv_worker.rb
@@ -1,5 +1,3 @@
require "s3_file_uploader"

class GenerateGlobalExportCsvWorker
include Sidekiq::Worker

Expand All @@ -10,8 +8,6 @@ def perform(export_params)
export_params["exclude_spam"],
).call

s3_file = S3FileUploader.save_file_to_s3(filename, contents)

GlobalExportNotification.notification_email(export_params["notification_email"], s3_file.key).deliver_now
GlobalExportNotification.notification_email(export_params["notification_email"], filename, contents).deliver_now
end
end
17 changes: 0 additions & 17 deletions lib/s3_file_uploader.rb

This file was deleted.

19 changes: 0 additions & 19 deletions spec/mailers/global_export_notification_spec.rb

This file was deleted.

38 changes: 0 additions & 38 deletions spec/workers/generate_global_export_csv_worker_spec.rb

This file was deleted.

0 comments on commit 4d333ec

Please sign in to comment.