在Rails上的浏览器游戏中基于时间的操作

时间:2020-12-24 12:38:02

I want to make a game in rails (not with flash, just html). Every action should take some time to execute. For example, user can send an action to his hero "go learn ". It should lasts for 10 minutes. What's the best way to implement it?

我想用rails做一个游戏(不是用flash,只是用html)。每一个动作都需要一定的执行时间。例如,用户可以发送一个动作给他的英雄“去学习”。应该持续10分钟。最好的实现方法是什么?

I want to store player tasks in my database, but how should I do their execution?

我想在我的数据库中存储播放器任务,但是我应该如何执行它们呢?

  • 1 way: when user log in or do something, check his tasks and look for finished ones.
  • 1方法:当用户登录或做某事时,检查他的任务并寻找完成的任务。
  • 2 way: check tasks on my app every X seconds and look for finished ones.
  • 2方法:每隔X秒在我的应用上检查一次任务,然后寻找完成的任务。
  • 3 way: use something like Delayed Job gem. Do you think its good for my problem?
  • 方法:使用一些延迟的工作宝石。你认为这对我的问题有好处吗?

2 个解决方案

#1


2  

You could use delayed job, to run the task.With that there is problem that you will have tomanage "many" workers when there is extra load on the site, but its not that bad either, its doable as long as it "runs" every task exactly after 10 minutes.

您可以使用延迟作业来运行任务。有了这个问题,当站点上有额外的负载时,你将不得不对“许多”员工进行管理,但也不是那么糟糕,只要它在10分钟后“运行”每一项任务,它都是可行的。

You can still use a combined approach using 1 & 2 which would generally work.

您仍然可以使用1和2的组合方法,这通常是可行的。

#2


0  

I am now researching for a solution to perform similar task and just recently came across a railscasts episode that I found worthy of noting down.

我现在正在研究执行类似任务的解决方案,就在最近,我遇到了一个值得注意的铁路列车事件。

Using custom deamons (and a number of other interesting topics) found here.

使用这里找到的自定义deamons(以及其他一些有趣的主题)。

P.S. I see that you have asked this question a while back. Could you please share how you ended up implementing your solution.

注:我知道你刚才问过这个问题。请分享一下你是如何实现你的解决方案的。

Cheers

干杯

#1


2  

You could use delayed job, to run the task.With that there is problem that you will have tomanage "many" workers when there is extra load on the site, but its not that bad either, its doable as long as it "runs" every task exactly after 10 minutes.

您可以使用延迟作业来运行任务。有了这个问题,当站点上有额外的负载时,你将不得不对“许多”员工进行管理,但也不是那么糟糕,只要它在10分钟后“运行”每一项任务,它都是可行的。

You can still use a combined approach using 1 & 2 which would generally work.

您仍然可以使用1和2的组合方法,这通常是可行的。

#2


0  

I am now researching for a solution to perform similar task and just recently came across a railscasts episode that I found worthy of noting down.

我现在正在研究执行类似任务的解决方案,就在最近,我遇到了一个值得注意的铁路列车事件。

Using custom deamons (and a number of other interesting topics) found here.

使用这里找到的自定义deamons(以及其他一些有趣的主题)。

P.S. I see that you have asked this question a while back. Could you please share how you ended up implementing your solution.

注:我知道你刚才问过这个问题。请分享一下你是如何实现你的解决方案的。

Cheers

干杯