Scheduled jobs?

What’s the recommended approach for running scheduled/periodic jobs in
JRuby? I was looking at RailsPeriodicalTaskServlet in Goldspike but
since Warbler seems to be going the way of JRuby-Rack I was wondering
if anyone had any other ideas.

I was thinking I could possibly spin up a JRuby thread but how would I
configure it so that it only started in one of the JRuby runtimes?
Secondly, how would I acquire one of the runtimes to do the work
(presumably I would need to do this to avoid any concurrency issues in
my Rails app)?

This blog entry (http://www.jkraemer.net/tags/quartz) has some info on
RailsPeriodicalTaskServlet and a second approach using Quartz, but I’d
like a more Ruby-centric approach.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, May 22, 2008 at 1:45 PM, Darcy S. [email protected]
wrote:

This blog entry (http://www.jkraemer.net/tags/quartz) has some info on
RailsPeriodicalTaskServlet and a second approach using Quartz, but I’d like
a more Ruby-centric approach.

Maybe GitHub - jmettraux/rufus-scheduler: scheduler for Ruby (at, in, cron and every jobs)

I use it on JRuby 1.1.1, runs fine.

Best regards,


John M. - http://jmettraux.wordpress.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I’m using it in jruby on rails apps too.

On Thu, May 22, 2008 at 3:22 AM, John M. [email protected]
wrote:


Fabio K.

Caelum - Ensino e Soluções em Computação

From many of the things I’ve read about threading in Ruby and Rails
(e.g., http://wiki.rubyonrails.org/rails/pages/HowTosWorkerThreads) I
still feel like I need to be concerned about calling ActiveRecord or
ActionMailer methods from a scheduled task in a Rails app. Even
though JRuby’s threading seems to be more robust than MRI’s It seems I
would still have to do something to work around Rails’ single threaded
model. Is this correct?

Fabio, could you give some details / advice on that? I’d suspect that
it’s pretty easy to mess things up using ruby-land threads to schedule
tasks inside a rails app…

Regards,
Kim

Not having used rufus-scheduler before, I can’t speak to how it deals
with Rails’s threading issues, but the other two methods mentioned in
the original post both deal with it the same way that RailsServlet does
– each thread gets its own runtime.

On our project, we chose quartz-rails over RailsPeriodicalTaskServlet
because it provides a lot of options w.r.t. scheduling the jobs, since
we want a couple of the jobs to run once per day, at a particular time
of day. In a future iteration, our project may add a ruby wrapper around
some of quartz’s scheduling capabilities so that users can control when
certain jobs are run.


Matt

Ruby Threads in JRuby are real Java native threads, so you won’t have
any
problems (in normal conditions, as concurrent apps are always very
complicated).
Just remember that you have many jruby runtimes, and each of them is
going
to start the same ruffus schedulers.

I had to do some ‘tricks’ to avoid starting many schedulers of the same
type, when only one would be sufficient. If you have code in your
config/initializers/ folder to start your schedulers, you could use
$servlet_context flags to ensure you aren’t starting the same schedulers
again.

ServletContextListeners could be also an alternative.

On Fri, May 23, 2008 at 7:28 AM, Kim A. [email protected] wrote:


http://www.fabiokung.com

Caelum - Ensino e Soluções em Computação
http://www.caelum.com.br


Fabio K.

Caelum - Ensino e Soluções em Computação