Ruby 桌面应用程序中的后台作业
我正在开发一个用 Ruby 编写的跨平台 GUI 桌面应用程序。该应用程序将使用 MacRuby 在 Mac OS X 上提供 GUI,并在其他平台上使用 Qt 提供 GUI。该应用程序是一款多媒体工具,可用于翻录 CD 或 DVD 并将其编码为各种格式,或者将多媒体文件从一种格式转码为另一种格式。
这些任务非常耗时,因此必须在后台运行,以免在执行时冻结 GUI。此外,后台作业应该能够被取消和/或暂停,并且能够向 GUI 报告状态和进度。可能还需要为作业分配优先级,以便较高优先级的作业在较低优先级的作业之前运行,并且还需要在作业之间具有依赖性,以便作业在其所有依赖性完成之前不会开始执行。
我的问题是:什么工具或技术最适合在 Ruby GUI/桌面应用程序中处理此类后台作业?我不想“滚动我自己的”作业管理器来生成进程或线程并管理作业的启动和停止等。
编辑:在发布这个问题后,我意识到我曾经对 C++ 解决方案提出了一个非常类似的问题后退。我对此 Ruby 解决方案的要求与我在此处发布的 C++ 解决方案的要求相同:C++ master/worker
I am working on a cross-platform GUI desktop application, written in Ruby. The application will use MacRuby to provide the GUI on Mac OS X, and will use Qt for the GUI on other platforms. The application is a multimedia tool that will allow for such things as ripping CDs or DVDs and encoding them to various formats, or transcoding multimedia files from one format to another.
These tasks are time consuming and therefore must be run in the background so as not to freeze the GUI while they are executing. Furthermore, the background jobs should be able to be canceled and/or paused, and be able to report status and progress to the GUI. There may also be a need to assign priorities to the jobs, so that higher priority jobs run before lower priority jobs, and also to have dependencies between jobs so that a job does not start executing until all of its dependencies have completed.
My question is: what tools or techniques would be best for handling these kinds of background jobs in a Ruby GUI/desktop application? I'd prefer not to "roll my own" job manager to spawn processes or threads and manage the starting and stopping of jobs, etc.
Edit: after posting this question I realized I had asked a very similar question for a C++ solution a while back. My requirements for this Ruby solution are the same as what I had posted for the C++ solution here: C++ master/worker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,我遇到的大多数 Ruby 后台作业运行程序都是针对 Rails 的。
这可能比您正在寻找的级别要低一些,但是EventMachine浮现在脑海中。如果您准备编写自己的高级作业/依赖项代码,则可以使用 EM 来为其提供动力并处理线程(或分叉,如果您愿意的话)的肮脏工作。不确定是否要暂停...
我建议查看 EventMachine::Deferrable 和 EventMachine::DeferrableChildProcess 看看它们是否有效。
Unfortunately most of the Ruby background job runners I've run across are intended for Rails.
This might be a little lower-level than you're looking for, but EventMachine comes to mind. If you're up for writing your own high-level Job/Dependency code, you could use EM to power it and handle the dirty work of threading (or forking, if you prefer). Not sure about pausing...
I would recommend looking at EventMachine::Deferrable and EventMachine::DeferrableChildProcess to see if they might work.
我最近使用 resque 在 ruby 项目中执行后台作业。诚然,它是一个 Rails 应用程序,但据我所知,没有什么可以阻止某人在桌面应用程序中使用它,只要它与 MacRuby 兼容并且您不介意安装 Redis。
I recently used resque for doing background jobs in a ruby project. Granted, it was a Rails app, but as far as I know, there's nothing preventing someone from using it in a desktop app, provided it's compatible with MacRuby and you don't mind installing Redis.