jruby on Rails 调度选项

发布于 2024-10-06 15:29:44 字数 1210 浏览 7 评论 0原文

我正在 Rails 上使用 JRuby 1.5.6 为自己构建一个应用程序,该应用程序将定期消失并检索我也订阅的任何 RSS 播客。

我选择 JRuby 主要是因为我熟悉 Java,希望利用 Rails 框架,最重要的是,当 Ruby 达不到我的要求时,我能够在 Java 中执行“繁重”任务。到目前为止(我仍处于开发的早期阶段)这种混合方法一直运行得非常好。

我现在需要将定期和长时间运行的任务调度到后台进程。我的要求是拥有一个数据库支持的调度系统,理想情况下,该系统有良好的文档记录、当前维护且干净。

我现在的问题是,经过很多天的研究合适的自 gem 打包解决方案后,由于我使用 JRuby,我似乎只剩下很少的选择。

我尝试过的一些宝石...

rufus Scheduler

在我对它的界面和文档感到满意之前使用过它,但是缺乏数据库持久性,因此无法满足我的要求。

delayed_job

我理想的解决方案是delayed_job。良好的文档,仍在维护和数据库支持,但是,由于 ObjectSpace 被关闭,在 JRuby 下会中断(但是我们可以通过重新启用来修复此问题),但更致命的是对守护进程 gem 的依赖,它会抛出“fork is unsafe and unavailable”由于 JRuby 实现中的限制,JRuby 上默认出现“错误”。

github 上有一个不依赖守护进程的 fork,但是我不高兴切换到主开发分支之外的 fork,而且我仍然面临 ObjectSpace 问题,我不确定它的性能影响。

quartz-jruby

虽然之前有各种基于石英的宝石,这个最近的产品< /a> 是提供光滑的类似 Ruby 的界面的另一种尝试。然而,文档很少,我不确定这是否可以由数据库支持,我的直觉是它不是。

问题

虽然我在这里只突出显示了 3 个选项,但我知道还有其他选项可用。然而,我一直无法找到解决方案来勾选所有 3 个要求框(文档、维护、数据库支持)。

所以问题是...

还有其他人遇到过这种情况并提出解决方案吗?

有没有人设法让delayed_job以任何形式工作?

有没有我忽略的更好的解决方案可以满足我的需求?

I'm using JRuby 1.5.6 on Rails to build myself an application that will periodically go away and retrieve any RSS podcasts that I have subscribed too.

I've chosen JRuby primarily because I'm familiar with Java, wish to utilise the Rails framework and most importantly I'm able to perform the "heavy lifting" tasks in Java when Ruby falls short of my requirements. Up to now (and I'm still in the early stages of development) this hybrid approach has been working extremely well.

I'm now at a point where I'm needed to implement scheduling of periodic and long running tasks to a background process. My requirements are to have a database backed scheduling system that is, ideally, well documented, currently maintained and clean.

My problem now is that after many days of researching suitable off the self gem packaged solutions, I appear to be left with very few options because of my use of JRuby.

Some of the gems I've tried...

rufus scheduler

Having used this before I'm happy with it's interface and documentation, however there is a lack of database persistence, hence a deal breaker for my requirements.

delayed_job

My ideal solution would be delayed_job. Good documentation, still being maintained and database backed, however, breaks under JRuby due to ObjectSpace being turn off (we can however fix this by re-enabling) but more fatally the dependence on the daemons gem which throws a "fork is unsafe and disabled by default on JRuby" error due to limitations within the JRuby implementation.

There is a fork on github that doesn't have a dependence on daemons, however I'm not happy switching to a fork off the main development branch and I'm still left with the ObjectSpace issue which I'm unsure as to it's performance impact.

quartz-jruby

While there have been various quartz based gems before, this very recent offering is another attempt at providing a slick ruby-like interface. There is however minimal documentation and I'm unsure as to if this can be database backed, my gut feeling is that it is not.

The problem

While I've only highlighted 3 options here, I'm aware that there are others available. I've however not been able to find a solution to tick all 3 requirement boxes (docs, maintained, database backed).

So the questions are...

Has anyone else been in this situation and come up with a solution?

Has anyone managed to get delayed_job working in whatever form?

Are there any better solutions out there that I've overlooked and will satisfy my needs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

林空鹿饮溪 2024-10-13 15:29:44

我们在生产环境中使用 JRuby 下的 Delayed_job (collectiveidea/v1.8.4) 已经一年多了。
我们没有启用 ObjectSpace,也没有使用守护进程 gem。

创建了一个简单的 rake 任务

  namespace :product do
    desc "Start Delayed Job Worker"
    task :dw => :environment do
      Delayed::Worker.new.start
    end
  end

并以依赖于操作系统的方式对其进行守护进程。在Linux上,

nohup jruby -S rake product:dw > $log_dir/delayed_job_console.log  2>&1 &

We have been using delayed_job (collectiveidea/v1.8.4) under JRuby in production for over an year now.
We have not enabled ObjectSpace and also we do not use daemons gem.

Created a simple rake task

  namespace :product do
    desc "Start Delayed Job Worker"
    task :dw => :environment do
      Delayed::Worker.new.start
    end
  end

and daemonize it in the OS dependent way. On linux,

nohup jruby -S rake product:dw > $log_dir/delayed_job_console.log  2>&1 &
你的往事 2024-10-13 15:29:44

我推荐 resque 作为排队系统。 Resque 与 DelayedJob 类似,但在我看来要好得多。它在 GitHub 上开发,并用作他们的排队系统。我也在生产中使用它近一年了,我对它非常满意。

Resque 绝对支持 JRuby,您只需拥有一个简单的调度程序即可获得计划的作业。有些人推荐 resque-scheduler,尽管我喜欢保持简单并使用 clockwork 它有一个很好的 DSL,用于编写简单的类似 cron 的任务来排队调度程序(请参阅:发条自述文件)。这样,您就可以像这样安排事情:

every(1.hour, 'tasks.alert') { Resque.push(:cron, :class => 'TaskAlert', :args => []) }

I would recommend resque as the queueing system. Resque is similar to DelayedJob, but in my opinion much better. It was developed at GitHub and is used as their queueing system. I've also been using it in production for almost a year and I've been very happy with it.

Resque definitely has JRuby support, and all you have to do to get scheduled jobs is have a simple scheduler. Some recommend resque-scheduler, though I like to keep it simple and use clockwork which has a nice DSL for writing simple cron-like tasks to queue up schedulers (see: clockwork README). With that, you can just schedule things like so:

every(1.hour, 'tasks.alert') { Resque.push(:cron, :class => 'TaskAlert', :args => []) }
七分※倦醒 2024-10-13 15:29:44

检查 https://github.com/kares/jruby-rack-worker
这允许在jruby环境下delayed_job解决方案。
工作仍在进行中。
在撰写本文时,我的经验是它对于单个工人来说效果很好。
尽管我很难让更多的工人运行。

Check https://github.com/kares/jruby-rack-worker
This allows delayed_job solution under jruby environment.
Still work in progress.
At the time of writing, my experience is that it works fine with a single worker.
Though I have difficulties at making additional workers run.

痴骨ら 2024-10-13 15:29:44

我最初在 10 年 12 月提出这个问题,此后开发了一个解决方案,我认为该解决方案值得发回以供其他人参考。

正如其他人所指出的那样,可以让delayed_job之类的库与JRuby一起使用,对于某些人来说,这可能是一个可以接受的解决方案。然而,我不想要一个需要运行额外进程的解决方案,考虑到这一点,我开发了一个利用 Java 的 Executor 框架并将其与 ActiveRecord 集成的 gem。

结果是 acts_as_executor,它允许 Rails 3.x 应用程序与执行器和任务交互(将在一个适当的 Java 线程)就像任何其他 ActiveRecord 模型一样。

我最近将 gem 移至候选版本 1。请查看 GitHubRubygems

注意,出于某种原因,RubyGems 默认页面仍然显示 beta2。然而 rc1 仍然是最新版本。

I originally asked this question in Dec '10 and have since developed a solution that I thought would be worth posting back for others to reference.

As others have pointed out, it is possible to get libraries like delayed_job working with JRuby and for some this might be an acceptable solution. I however didn't want a solution that required an additional process running and with that in mind I have developed a gem that utilises Java's Executor framework and integrates it with ActiveRecord.

The result is acts_as_executor which allows a Rails 3.x application to interact with executors and tasks (which will run in a proper Java thread) just as it would any other ActiveRecord model.

I've recently moved the gem to release candidate 1. Take a look at GitHub and Rubygems.

N.B. RubyGems default page still shows beta2 for some reason. rc1 is still the latest release however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文