-
-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make previously generated reports available for download #10629
Changes from all commits
5f3329b
f84a298
a4e377e
20c6b4a
1bb5b78
17db3a9
a339877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,12 @@ def done? | |
end | ||
|
||
def result | ||
@result ||= read_result | ||
blob = ActiveStorage::Blob.create_and_upload!(io: File.open(filename), filename: filename) | ||
ActiveStorage::PurgeJob | ||
.set(wait: Rails.configuration.active_storage.service_urls_expire_in) | ||
.perform_later(blob) | ||
File.unlink(filename) | ||
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, so we still store the file and then upload it. I was hoping to avoid the local storage and upload directly. It means that we need to find a different implementation of ReportJob#done?. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was hoping so too. I wanted to get rid of the first temp save. But from what I understand of |
||
blob | ||
end | ||
|
||
private | ||
|
@@ -22,12 +27,6 @@ def write(result) | |
File.write(filename, result, mode: "wb") | ||
end | ||
|
||
def read_result | ||
File.read(filename) | ||
ensure | ||
File.unlink(filename) | ||
end | ||
|
||
def filename | ||
Rails.root.join("tmp/report-#{job_id}") | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,5 +249,7 @@ module ::Reporting; end | |
config.active_storage.variable_content_types += ["image/svg+xml"] | ||
|
||
config.exceptions_app = self.routes | ||
|
||
config.active_storage.service_urls_expire_in = 60.minutes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that his applies for all ActiveStorage URLs? We should probably limit this to the reports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. I have not thought of that. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
let(:enterprise) { create(:enterprise) } | ||
let(:params) { {} } | ||
let(:format) { :csv } | ||
let(:configured_job) { instance_double(ActiveJob::ConfiguredJob) } | ||
|
||
it "generates a report" do | ||
job = ReportJob.new | ||
|
@@ -20,17 +21,25 @@ | |
job = ReportJob.perform_later(*report_args) | ||
expect(job.done?).to eq false | ||
|
||
# This performs the job in the same process but that's good enought for | ||
# testing the job code. I hope that we can rely on the job worker. | ||
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true | ||
job.retry_job | ||
perform_enqueued_jobs(only: ReportJob) | ||
Comment on lines
-23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much better, thank you! |
||
|
||
expect(job.done?).to eq true | ||
expect_csv_report(job) | ||
end | ||
|
||
it 'sets a purge job on blob creation' do | ||
allow(ActiveStorage::PurgeJob).to receive(:set).and_return(configured_job) | ||
allow(configured_job).to receive(:perform_later) | ||
job = ReportJob.new | ||
job.perform(*report_args) | ||
job.result | ||
|
||
expect(ActiveStorage::PurgeJob).to have_received(:set).with(hash_including(:wait)) | ||
end | ||
|
||
def expect_csv_report(job) | ||
table = CSV.parse(job.result) | ||
blob = job.result | ||
table = CSV.parse(blob.download) | ||
expect(table[0][1]).to eq "Relationship" | ||
expect(table[1][1]).to eq "owns" | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this method doesn't exist yet in this commit.