I'm transferring a Ruby app I once made into Rails. Now the app does some calculations that take a while (up to infinity (in theory) if you like :p). To show a user the status of everything, I previously used the console. Now, obviously, I want my browser to show this.
我将一个Ruby应用程序移植到Rails中。现在,这个应用程序做一些计算需要一段时间(如果你喜欢的话,可以在理论上达到无穷大:p)。为了向用户显示所有内容的状态,我之前使用了控制台。显然,我想让浏览器显示这个。
Does anyone has any pointers where to start reading/exmples/gems/ideas? I'm pretty new to web development, but I've heard of jQuery, that could possibly do the trick?
有没有人有什么建议可以开始阅读/exmples/gems/想法?我对web开发很陌生,但是我听说过jQuery,它可能会有这个功能吗?
4 个解决方案
#1
2
As per my understanding you have two options to do this
根据我的理解,你有两个选择
1 - using some kind of a server push method to be implemented. You may use following components
使用某种要实现的服务器推送方法。您可以使用以下组件
juggernaut (http://juggernaut.rubyforge.org/ ) http://www.ape-project.org/
巨人(http://juggernaut.rubyforge.org/)http://www.ape-project.org/
2 - Using PeriodicalUpdater with JQuery. This will send a request to the server in a given time interval.
2 -使用JQuery周期性更新。这将在给定的时间间隔内向服务器发送请求。
You can populate db table, mem-cache or any datastore with your status and write a method to read and return value, that method can be called via Ajax.PeriodicalUpdater
您可以用您的状态填充db表、内存缓存或任何数据存储,并编写一个读取和返回值的方法,该方法可以通过Ajax.PeriodicalUpdater调用
I have done this, but this is killing the performance as it request the server (in mycase it was every 5 seconds)
我已经这样做了,但是这将破坏它请求服务器时的性能(在mycase中是每5秒一次)
Even though I personally haven't done, I prefer the server-push option is the methodical way to go
尽管我个人还没有这样做,但我更希望服务器推送选项是一种有条理的方式
HTH
HTH
cheers
干杯
sameera
sameera
#2
3
If your computations take a long time you will want to pass them to some background job processor. There are several several gems that can help you do this. Here are a few with tutorial how to use them with Rails.
如果您的计算花费很长时间,您将希望将它们传递给一些后台作业处理器。有几个宝石可以帮助你做到这一点。这里有一些关于如何使用Rails的教程。
-
Sidekiq - Railscasts
Sidekiq——Railscasts
-
Delayed Job (Revised) - Railscast
延迟作业(修改)- Railscast
-
Delayed Job - Railscast
延迟的工作——Railscast
-
Resque - Railscast
Resque——Railscast
Providing a web interface to display the processing status of the calculation can be done in a number of ways. One way might be with polling.
提供一个web界面来显示计算的处理状态,可以通过多种方式完成。一种方法可能是使用轮询。
- Polling for Changes - Railscast
- 对更改的轮询—Railscast
#3
1
Rails live streaming currently in rails 4. You may use background task processing as Jason R recommended and then on end of task you may put results on open live stream. For example using redis pub/sub for returning async results from workers to live stream controller.
当前Rails 4中的Rails实时流。您可以按照Jason R的建议使用后台任务处理,然后在任务结束时,您可以将结果放在open live stream上。例如,使用redis pub/sub从工作者返回异步结果到活动流控制器。
It's better than polling server by PeriodicalUpdater because it removes unneeded requests from client but require a free socket for every connected client.
它比轮询服务器更好,因为它可以从客户端移除不需要的请求,但需要为每个连接的客户机提供一个免费的套接字。
#4
0
I just find super-tool :) Add this script to your project:
我刚刚找到超级工具:)把这个脚本添加到你的项目中:
<script src='https://gist.githubusercontent.com/vitalyp/9441352/raw/5be994fbc78bd2bcc7ad31192f095c888d02f819/myconsole.js'></script>
and somewhere in document.ready
(or from browser console), envoke function:
并在文档。准备(或从浏览器控制台),envoke函数:
pop_console();
It displays a window with console.log(...)
strings.
它显示一个带有console.log(…)字符串的窗口。
#1
2
As per my understanding you have two options to do this
根据我的理解,你有两个选择
1 - using some kind of a server push method to be implemented. You may use following components
使用某种要实现的服务器推送方法。您可以使用以下组件
juggernaut (http://juggernaut.rubyforge.org/ ) http://www.ape-project.org/
巨人(http://juggernaut.rubyforge.org/)http://www.ape-project.org/
2 - Using PeriodicalUpdater with JQuery. This will send a request to the server in a given time interval.
2 -使用JQuery周期性更新。这将在给定的时间间隔内向服务器发送请求。
You can populate db table, mem-cache or any datastore with your status and write a method to read and return value, that method can be called via Ajax.PeriodicalUpdater
您可以用您的状态填充db表、内存缓存或任何数据存储,并编写一个读取和返回值的方法,该方法可以通过Ajax.PeriodicalUpdater调用
I have done this, but this is killing the performance as it request the server (in mycase it was every 5 seconds)
我已经这样做了,但是这将破坏它请求服务器时的性能(在mycase中是每5秒一次)
Even though I personally haven't done, I prefer the server-push option is the methodical way to go
尽管我个人还没有这样做,但我更希望服务器推送选项是一种有条理的方式
HTH
HTH
cheers
干杯
sameera
sameera
#2
3
If your computations take a long time you will want to pass them to some background job processor. There are several several gems that can help you do this. Here are a few with tutorial how to use them with Rails.
如果您的计算花费很长时间,您将希望将它们传递给一些后台作业处理器。有几个宝石可以帮助你做到这一点。这里有一些关于如何使用Rails的教程。
-
Sidekiq - Railscasts
Sidekiq——Railscasts
-
Delayed Job (Revised) - Railscast
延迟作业(修改)- Railscast
-
Delayed Job - Railscast
延迟的工作——Railscast
-
Resque - Railscast
Resque——Railscast
Providing a web interface to display the processing status of the calculation can be done in a number of ways. One way might be with polling.
提供一个web界面来显示计算的处理状态,可以通过多种方式完成。一种方法可能是使用轮询。
- Polling for Changes - Railscast
- 对更改的轮询—Railscast
#3
1
Rails live streaming currently in rails 4. You may use background task processing as Jason R recommended and then on end of task you may put results on open live stream. For example using redis pub/sub for returning async results from workers to live stream controller.
当前Rails 4中的Rails实时流。您可以按照Jason R的建议使用后台任务处理,然后在任务结束时,您可以将结果放在open live stream上。例如,使用redis pub/sub从工作者返回异步结果到活动流控制器。
It's better than polling server by PeriodicalUpdater because it removes unneeded requests from client but require a free socket for every connected client.
它比轮询服务器更好,因为它可以从客户端移除不需要的请求,但需要为每个连接的客户机提供一个免费的套接字。
#4
0
I just find super-tool :) Add this script to your project:
我刚刚找到超级工具:)把这个脚本添加到你的项目中:
<script src='https://gist.githubusercontent.com/vitalyp/9441352/raw/5be994fbc78bd2bcc7ad31192f095c888d02f819/myconsole.js'></script>
and somewhere in document.ready
(or from browser console), envoke function:
并在文档。准备(或从浏览器控制台),envoke函数:
pop_console();
It displays a window with console.log(...)
strings.
它显示一个带有console.log(…)字符串的窗口。