-
-
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
Make previously generated reports available for download #10629
Conversation
The failing spec is ok on my machine .... |
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.
Great work, thank you!
I think that we should put this on hold until this is merged:
We will need to change a few things afterwards. I also have some ideas for improvements. For example, this version doesn't allow reports to take longer than 10 seconds while some reports take 10 minutes. So we need a way to display the message after 10 seconds but still allow the download of the report later when it's done.
I'm happy to help with this and co-work on this pull request. Let's just wait for the first PR to be merged though.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I have not thought of that.
end | ||
def blob_or_message | ||
Timeout.timeout(ReportsHelper::JOB_TIMEOUT) { | ||
blob = @report.report_from_job(report_format, spree_current_user, report_class, params) |
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.
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) |
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.
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 comment
The 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 create_and_upload
, you need to have first a local temp file to then create a blob.
# 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) |
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.
Much better, thank you!
I'm currently doing some small iterations to ship improvements quickly. Here's the next pull request: I just looked through your commits again and I think that the change in background processing means that it's better to start fresh. You are right that the official Active Storage API requires the file first but I found a workaround which I have stashed on my local machine at the moment. I'll see if I can show you something by tomorrow. |
Work in progress: |
Hello @mkllnk ,
Front: a link that points to a method
In the
If you think this snippets can be of any value, you can use it. |
That's awesome research. And I wonder if we can still simplify the solution. Have a look at my PR: What I'm missing there is the expiry in the link which should be easy to add. But I'm also wondering what the default Rails controller does then. Is it just displaying something like "this is expired"? That would be good enough. We don't need to implement our own controller action and flashes if Rails does this for us. Can you find out what Rails displays by default and if we can customise it? It would be good to maybe translate based on a user login or put our own layout around it. Using the Rails controller also means that we can direct people straight to the CDN and we don't have to proxy the file once it's uploaded. This is especially useful once we include that link in an email sent after the report was generated. |
Would you like to work on the expiry in the link and in the 10 second timeout within the controller? I'm now offline till Tuesday. So you can go wild without me interfering. 😉 |
I just tried adding I'm not sure if we can customise the Rails controller at all and if it's worth it. |
Hello @mkllnk , I have tried many combinations to try to figure out how to do this. I got help from that blog post
And contrary to what the doc says, The But I never could get a binding stop in a
The I think your idea to display the link once the report is done is good. But that would mean a second message to display after a first one that says report processing take a lot of time. Which implies another get/post. |
Wow, thanks for that research.
Yes. I guess that we can use the websocket (cable) connection to push the event of the generated report to the browser. But that would be the first push event in OFN. I need to learn how do that. 😄 |
@mkllnk @cyrillefr should we close this? Or is there still anything here we would like to keep? |
Yes, this has been replaced. Thank you @cyrillefr for all your input here. |
What? Why?
What should we test?
a link to a report if everything ok, or a flash message displaying an error notice.
To change the validity of the url:
config.active_storage.service_urls_expire_in
inconfig/application.rb
Timeout generation is set to 10 second and can be changed in
app/helpers/reports_helper.rb
Notes
Display when user wants to download report that is not valid no more due to time is not yet implemented(white screen).
I did not make use of Stimulus etc., but rather did it the "classical" way because too many options for the report(background or not, screen or pdf/xlsx).