Skip to content

A JRuby implementation of the Quartz scheduling framework that makes it easy to integrate into Ruby and Rails based projects.

License

Notifications You must be signed in to change notification settings

techwhizbang/jruby-quartz

Repository files navigation

= jruby-quartz

== Instructions

Requires the following jars in your application container and if running with just jruby place these in your $JRUBY_HOME/lib

commons-collections-3.2.x.jar
commons-logging.jar
log4j.jar
quartz-1.6.x.jar

If you are running a current version of JBoss you already have these!
If you are running an alternative container you will need to check it's lib
directory for the presence of these jars.

If you need these jars you can find them within the apache commons project and
the quartz jar on opensymphony

== Installation

  gem install git://github.com/techwhizbang/jruby-quartz.git

== Usage

The best way to leverage jruby-quartz is to simply extend the BaseScheduler and
implement any number of jobs you need to run.

For example all you need to do is specify some basic attributes including the
cron expression representing the frequency of the job(s) you want to with it:

class IntegrationScheduler < BaseScheduler

  def initialize(cron_expression)
    super
    @cron_expression = cron_expression
    @base_jobs_group = "IntegrationJobs"
    @base_triggers_group = "IntegrationTriggers"
  end
end

Then just extend the base job by putting all of the work you want to perform inside the
perform_job method.

class IntegrationJob < Jobs::BaseJob

  def perform_job
    worker_one = mock('worker class one', :whatever => "123")
    worker_two = mock('worker class two', :whatever => '123')
  end
end

If you are running Rails you can throw the schedule! method into a custom initializer.
An example of this would be like so:
Notice the Rails.env /container/, I defined custom environments that only run when
inside a Java container so that the schedule! method doesn't get fired off during
testing. 


if RUBY_PLATFORM =~ /java/

  LoggerOneScheduler.new("0 0/1 * * * ?").schedule!(Jobs::LoggerOneJob)
  LoggerTwoScheduler.new("0 0/2 * * * ?").schedule!(Jobs::LoggerTwoJob)

end

If you are planning on using this with a Rails stack, I would recommend using this
only with Rails 2.2 or higher because thread safety == 1 runtime

1 runtime means your schedule initializer is only called once.

=== Other

Problems, comments, and suggestions all welcome. techwhizbang@gmail.com or visit my blog
http://techwhizbang.com

About

A JRuby implementation of the Quartz scheduling framework that makes it easy to integrate into Ruby and Rails based projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages