提高控制器性能 Ruby on Rails
我在控制器中有以下代码
user = RegUser.create_reg_user(:some_parameters)
UserStuff.pass_user(some_parameters)
@hex = user.hex
@hex 被传递到视图并返回。 UserStuff 调用花费了相当多的时间,并且对于视图所需的 @hex 实际上并不重要。有没有办法继续返回 @hex 并加载视图,然后让 UserStuff 进行处理?
I have the following code in a controller
user = RegUser.create_reg_user(:some_parameters)
UserStuff.pass_user(some_parameters)
@hex = user.hex
The @hex is passed to the view and returned. The UserStuff call is taking a decent amount of time and is not actually important to the @hex which is needed for the view. Is there a way to go ahead and return the @hex and load the view and let the UserStuff process afterwards?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将这些长时间运行的“作业”卸载到后台队列。对您来说最简单的设置和运行可能是延迟作业。
我们使用 Beanstalkd (队列)和许多工作进程来处理所有长时间运行的任务(或任何需要超过 1-2 秒的任务)。
使用后台系统来处理此类作业的优点在于,您可以快速扩展,可以启动任意数量的工作进程,这些进程都从主队列(或延迟作业的数据库)中提取作业。
Offload these kinds of long running "jobs" to a background queue. Probably the easiest for you to get setup and running is Delayed Job.
We use Beanstalkd (a queue) and many worker processes to handle all long-running tasks (or any tasks that takes longer than 1-2 seconds).
The beauty of having a background system to process these kinds of jobs is that you can scale quickly, you can spin-up any number of worker processes which all pull jobs from a master queue (or DB in the case of Delayed Job).
延迟作业很好,而且易于使用。我推荐它。
Delayed Job is good, and easy to use. I recommend it.