jruby on rails scheduling options
Asked Answered
A

4

13

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?

Aristotelianism answered 8/12, 2010 at 16:9 Comment(1)
Update I thought it worth posting the final solution I settled upon for using with JRuby, now at 1.7.2. My current setup uses Sidekiq and Clockwork. It has proven to be a reliable long-term solutionAristotelianism
O
4

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 &
Orissa answered 10/2, 2011 at 1:31 Comment(1)
I think this is similar to run <rake jobs:work>, as you can see in [..]/gems/delayed_job-3.0.3/lib/delayed/tasks.rb --> task :work => :environment do Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'], :max_priority => ENV['MAX_PRIORITY'], :queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').sp lit(','), :quiet => false).startSedda
B
4

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 => []) }
Bejarano answered 12/2, 2011 at 16:52 Comment(0)
E
2

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.

Electra answered 18/4, 2011 at 21:2 Comment(1)
Was working fine, but then it gets locked every time. Do you have any idea?Jujube
A
1

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.

Aristotelianism answered 9/9, 2011 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.