使用axlsx创建延迟作业方式的Excel [英] Create an excel in delayed job method using axlsx

查看:142
本文介绍了使用axlsx创建延迟作业方式的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在模型中的延迟作业方法中生成一个excel文件。在当地工作正常。我正在使用调度程序在heroku中运行延迟作业。

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

我使用的是delayedjob 4.1。

I'm using delayedjob 4.1.

推荐答案

由于@Зелёный已经回答了,你在Heroku上的dyno将有一个只读文件系统。从某种意义上说,您的文件不会在您的dyno重新启动之间持续存在,并且不能保证它们将在任何两个请求之间持续存在。以下是文件摘录

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:


每个dyno都有自己的临时文件系统,不与任何其他dyno共享,只要断开即可丢弃。这个文件系统使用slug归档文件,所以一次性的dynos可以充分利用在应用程序中部署的任何东西。

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.

你可以使用#{Rails.root} / tmp 文件夹作为临时文件夹,但需要将文件上传到某些外部存储器(S3,某些CDN等)。 Heroku有一些插件可以很容易地处理。

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.

这篇关于使用axlsx创建延迟作业方式的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆