简体   繁体   中英

Generating large xlsx file with axlsx_rails gem using delayed_job

I have a rails application and some huge xlsx files to generate and, although the axlsx_rails works really well in generating these files, when the number of lines surpasses 60000 there is a long time waiting until the download window pops up.

I was suggested to use delayed_job. As a beginner, I barely understand how delayed_job works in "normal" way, when you have a method to call `.delay` on, but in this case the gem do all the work, so how could I put it on a delayed job? or in other words, what should I call the `.delay` on?

My whole implementation of axlsx_rails was done as in the following tutorial: https://www.sitepoint.com/generate-excel-spreadsheets-rails-axlsx-gem/

It's likely they meant to use ActiveJob. You can find documentation for it here:

http://edgeguides.rubyonrails.org/active_job_basics.html

If your'e using Rails 5.x you can use the async queue adapter by putting this in your application.rb config file:

config.active_job.queue_adapter = :async

If you're using Rails 4.x you will need to use a job back end to perform asynchronous tasks such as sidekiq:

https://github.com/mperham/sidekiq/wiki/Active-Job

Sidekiq will also require you to install Redis to store the jobs:

https://github.com/mperham/sidekiq/wiki/Using-Redis

Here's a guide to build and configure Redis:

https://redis.io/topics/quickstart

The section of interest is "Installing Redis More Properly" although you can bypass a lot of that manual work by following the instructions on their downloads page here:

https://redis.io/download

After you run the make, the utils folder has a setup script that you can just run and it will do all of the setup in the quickstart guide for you except copying the executable to your /usr/local/bin directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM