如何在 Rails 中实现触发器?
我的问题似乎不是一个独特的问题。基本上,我有一个相当昂贵的进程,需要定期运行,但前提是用户触发特定状态。
例如,我有一个“问卷”系统,我分析结果并根据分析提供建议。分析和提出建议是一个昂贵的过程,有时需要 10-20 秒,并且可能会随着数据集的增加而增加。顺便说一句,我目前正在寻找提高该算法性能的方法。
我对此的想法是为该用户实现一个状态,表明分析/建议已过期,轮询该状态,如果过期则运行昂贵的流程。然后,当用户完成调查问卷时,我会将此状态设置为过期。
我当前的系统是rails 3.0,ruby 1.9.2,MySQL运行在EC2服务器上。我目前正在使用 DelayedJob 将此进程推送到后台作业,但我尚未实现状态/触发器。
总而言之,我的问题是 1)在给定的场景下,这是否是正确的架构? 2)是否有任何可以与 Rails 一起使用的 gem 或实现?
My problem doesn't seem like a unique one. Basically I have a fairly expensive process that needs to run regularly but only if a user triggers a certain state.
For example, I have a "questionnaire" system and I analyze the results and provide recommendations from the analysis. The analysis and making the recommendations is an expensive process, sometimes 10-20s and could increase as the data set increases. By the way, I'm currently looking at ways to improve the performance of this algorithm.
My thoughts on this are to implement a state for that user that says that the analysis/recommendations are expired, poll this state and if it is expired run the expensive process. I would then set this state to expired when the user completes a questionnaire.
My current system is rails 3.0, ruby 1.9.2, and MySQL running on EC2 servers. I'm currently using DelayedJob to push this process to a background job but I haven't implemented the state/trigger.
So in summary my question is 1) Is this even the correct architecture given the scenario? and 2) Is there any gem or implementation of this that I can use that works with Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以构建一个快速 rake 任务来检查需要分析的调查问卷,并排队作业以供 DJ 处理。然后,您可以使用 Clockwork 按预定义的时间间隔运行 rake 任务。
因为您使用的是 EC2,所以您无需支付任何额外费用来运行轻量级 Clockwork 进程,并且您的 rake 任务可以轻松继承与您的应用程序相同的环境,而不存在被 HTTP 请求触发的风险。
You could build a quick rake task to check for questionnaires that need analysis and queue jobs for processing with DJ. Then you can run the rake task at pre-defined intervals with Clockwork.
Because you're on EC2, you won't have to pay anything additional to run the lightweight Clockwork process, and your rake task can easily inherit the same environment as your application without any risk of being triggered by an HTTP request.