Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jruby on rails scheduling options

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?

like image 735
Phil Ostler Avatar asked Dec 08 '10 16:12

Phil Ostler


4 Answers

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 &
like image 127
so_mv Avatar answered Nov 07 '22 07:11

so_mv


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 => []) }
like image 4
Idris Mokhtarzada Avatar answered Nov 07 '22 06:11

Idris Mokhtarzada


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.

like image 2
user708617 Avatar answered Nov 07 '22 07:11

user708617


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.

like image 1
Phil Ostler Avatar answered Nov 07 '22 08:11

Phil Ostler