PDF 生成过程完全完成后调用 Rail 的操作。 - 虾 +轨道
我正在使用 PRAWN 在 Rails 中生成一本 pdf 书。 在我的应用程序中,我需要找到生成的 pdf 书籍的文件大小。因此,我正在寻找一种在 pdf 生成过程完全完成时调用另一个操作(评估文件大小)的方法。 有没有一种方法可以将代码放在调用该操作的 Prawn 文件末尾?或者任何其他选项 - 等待 pdf 生成过程结束然后调用该操作?
任何形式的提示将不胜感激。
I'm using PRAWN to generate a pdf book in Rails.
In my application, I need to find the file-size of thus generated pdf book. So, I'm looking for a way that calls another action (which evaluates the file size ) when the pdf generation process is completely finished.
Is there a way which I can put the code at the end of Prawn file that calls that action ? Or any another option - which waits until the pdf generation process is over and then calls that action ?
Any sort of hint will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于这种事情,可能值得尝试resque
It might be worth trying resque out for this sort of thing
在 Rails 中,
action
是控制器上的公共实例方法,充当某些匹配的 HTTP 请求路由到的端点。action
与此时此地的 HTTP 请求(action
是端点)以及 HTTP 响应(action
)密切相关。 > 正在建设中。这可能是语义上的,但您不想在完成长时间运行的后台作业后调用操作。
相反,无论长时间运行的后台作业完成后需要运行什么代码,该代码都应该位于模型或某些实用程序类中。
请参阅delayed_job 和resque 以了解在Rails 中易于使用的后台作业队列/运行程序的实现。
In Rails, an
action
is a public instance method on a controller which serves as an endpoint to which certain matching HTTP requests are routed. Anaction
is intimately tied to the here-and-now of the HTTP request for which theaction
is the endpoint and the HTTP response which theaction
is building.This may be semantics, but you don't want to call an action after completion of a long-running background job.
Instead, whatever that code is that needs to run after completion of a long-running background job, that code should be in the model or in some utility class.
See delayed_job and resque for implementations of background job queues/runners that are simple to use in Rails.
delayed_job 还允许您创建异步作业
delayed_job also allows you to create asynchronous jobs