Create an excel in delayed job method using axlsx

耗尽温柔 提交于 2019-12-01 12:02:07

问题


I am trying to generate an excel file in my delayed job method in model. which is working fine in local. i'm using scheduler to run delayed jobs in heroku. Jobs are getting finished successfully without generating excel.

my delayed job method looks like:

def self.generate_excel     
Axlsx::Package.new do |p|
    p.workbook.add_worksheet(:name => "Stock Details") do |sheet|
       sheet.add_row ["S.No",  "ProductId", "Title"]
       products.each_with_index do |prods, index|
       sheet.add_row ["1", "1234", "product title"] 
               end
            end 
  p.serialize("#{Rails.root}/app/views/stock_details/stock_details.xlsx")
end

I'm using delayedjob 4.1.


回答1:


As @Зелёный has already answered, your dyno on Heroku would have a "read-only" filesystem. In a sense, your files will not be persisted between your dyno restarts and there is no guarantee that they will persist between any two requests. Here is an excerpt from the docs:

Each dyno has its own ephemeral file system, not shared with any other dyno, that is discarded as soon as you disconnect. This file system is populated with the slug archive so one-off dynos can make full use of anything deployed in the application.

You can use the #{Rails.root}/tmp folder as temporary folder, but you need to upload your files to some external storage (S3, some CDN, etc.). Heroku has some addons that makes it easy to handle.



来源:https://stackoverflow.com/questions/37360703/create-an-excel-in-delayed-job-method-using-axlsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!