English 中文(简体)
我如何把控制器方法作为背景任务?
原标题:How can I run a controller method as a background task?

我听到了各种背景任务工具(即:工作、营养、工作等),但从审视这些工具来看,它们似乎真正能够采用模型方法(例如,User.update_counters)。

我需要能够操作一种控制器方法,因为这种方法具有相当复杂的一套任务,使其他控制器方法和习俗班相互交织。

它的密集过程可耗5至10分钟,因此,我不干预其他用户的“正常”现场业务。

我误解这些其他工具如何发挥作用? 或者还有什么我不考虑?

最佳回答

公认的做事方式是把你的复杂逻辑推向模式,只让控制者指导请求和答复。 这就是“Fat模型和皮肤控制器”理论的说法。 将复杂逻辑转化成模型类别(不需要是活性记录类别),而且你可能要承担一个背景工具所要求的任务。

问题回答

如果你真的需要管理控制者的行动,那么你可以使用 cr子、植被或 cur。 但是,我建议把你的复杂逻辑变成一个模型或图书馆,以便你能够使用你所提到的一种背景工具,将其放在控制人之外。

你可能希望考虑把这一复杂的任务变成一项艰巨的任务。 你 tasks忙的任务仍然可以参考你的模式,因此建议你把与其相关的逻辑推向你们。

此外,因为你说,这项任务是万国邮联的约束,而且在执行该任务时,该地点会放慢。 (假定你是UNIX系统),以调整你的任务的优先次序。

我这样说,你的工作最好留给控制者处理。 如果你在系统运行时放弃整个系统的这一庞大进程,那么,我的第一个对策是假定我的工作不会像需要的那样动摇。 如果这个过程确实如此密集,以致整个系统瘫痪,那么它就成为夜间工作或下班期间的主要候选人。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签