客户提交表单以在 Rails 上创建 Cron 作业
好吧,我决定改进我在诗歌方面寻求帮助的内容,只是就此提出一个新问题。我相信,如果我知道一种方法,当客户端在我的 Rails 应用程序上提交表单时,就会运行 cron 作业,其中 cron 作业的时间由用户从下拉菜单中选择,我相信我可以完成以下任务。有没有办法做到这一点,我一直在谷歌上搜索想法,但还没有找到。
老问题
我正在尝试开发一个系统,允许用户将电影上传到我的网站,然后在特定时间播放。电影将连续流式传输,以便在某个时间(例如一小时后)播放队列中的下一部电影。我想知道是否有 gem 或脚本已经做到了这一点?或者什么是最好的方法来做到这一点,我认为用 cron 或延迟作业之类的工作来做到这一点,但我不认为这是最有效的方法。任何建议将不胜感激。
ps 我认为一种更简单的解释方法是,在 YouTube 上您可以对要播放的视频进行排队,因此可以在 Rails 中做类似的事情,这将有助于解决我的问题。
Okay I decided to improve on what I am asking for help with verse just opening a new question on this. I believe I can accomplish the below if I know of a way that when a client submits a form on my Rails app a cron job is run, where the time for the cron job is selected by the user from a drop down menu. Is there a way to do this, I have been googling around for ideas but haven't found one.
Old Question
I am attempting to develop a system that would allow a user to upload a movie to my site and then have it played back at a certain time. The movies would be continuously streamed, so that at a certain time say after an hour, the next movie in the queue would play. I am wondering is there a gem or script that already does this? Or what is the best way to go about doing it, I thought doing it with jobs like cron or delayed-job, but I don't think that's the most efficient way to do this. Any advice would be appreciated.
p.s. I think a simplier way to explain it is, on YouTube you can queue up videos to be played, so could one do something similiar in rails, this would help towards my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果用户决定播放的确切时间,您可以使用 rufus-scheduler gem 。
插入从用户那里获得的时间,如下所示:
您的
some_method
可以与 socket.io< 协同工作/a> 包装器,如 Juggernaut,它会向用户的浏览器发送一条消息,浏览器会执行一些 JS会获取视频并播放。您可以做的基本上就是打开浏览器窗口,当到达预定时间时,浏览器将获取适当的视频并播放它。
如果你需要实现一个视频排队系统,你可以让用户通过ID将他们想要的视频排队,然后通过视频结束时触发的回调函数调用队列中的下一个视频。回调将查询数据库以查找队列中的下一个视频,获取视频并播放它。
If the user gets to decide the exact time of playback, you could use the rufus-scheduler gem.
Plug in your Time obtained from the user like so:
Your
some_method
could work in tandem with a socket.io wrapper like Juggernaut, which would send a message to the user's browser, which would execute some JS that would fetch the video and play it.What you could do with this is basically sit around with your browser window open, and when the scheduled time is reached, the browser would fetch the appropriate video and play it.
If you need to implement a video queueing system, you could just enable users to queue up the videos they want to by ID, and then call the next video in the queue via means for a callback function which is triggered when the video has ended. The callback would query the database for the next video in the queue, fetch the video, and play it.
我在严重依赖计划任务的项目上使用了非常流行的 Whenever,它非常棒。它为您提供了一个很好的 DSL 来定义您的计划任务,而不必处理 crontab 格式。来自自述文件:
自述文件中的示例:
将用户定义的参数放入上面的查询中。就是这样。
I've used the extremely popular Whenever on projects that rely heavily on scheduled tasks, and it's great. It gives you a nice DSL to define your scheduled tasks instead of having to deal with crontab format. From the README:
Example from the README:
Put your user defined parameters in above query. thats it.
我认为您甚至不需要为前端调度做后台工作。
甚至不需要去寻找 Juggernaut 或任何 Cron Job 之类的东西。
这一切都可以简单地通过使用 JavaScript 来实现。
您可以使用 javascript 的 setTimeout() 和clearTimeout() 函数,或者在 ajax 调用之前添加 sleep() 。
步骤如下:
注意:不要忘记将 setTimeout() 分配给变量,以便您可以执行clearTimeout(the_variable)。
这是详细用法:http://www.w3schools.com/js/js_timing.asp
I don't believe you even need to do the background stuff for just front-end scheduling.
Need not to even go for Juggernaut or any Cron Job thingy.
This all can simply be achieved by using JavaScript.
You can either use javascript's setTimeout() and clearTimeout() functions or add a sleep() before your ajax call.
here are the steps:
Note: don't forget to assign the setTimeout() to a variable so that you can do clearTimeout(the_variable).
here is the detailed usage: http://www.w3schools.com/js/js_timing.asp