Timer Alternatives

I would like to write a Jruby script that starts a timer, tries to
complete something, and then fails if it times out. I took at look at
the
Ruby PLEAC page, and saw that this is typically done using the “timeout”
module. That module didn’t end up working for me, and I then found out
that it using that module with Jruby is not recommended.
Can anyone please suggest what I should use to set a timer using Jruby?
I
found the java.util.timer class in Java, but it seems a bit clunky. I
was
hoping there was something a bit more Ruby-ish. Is there any other
class
that anyone has had any luck with?
Thanks!
Tom Purl

I’ve had success with this in the past in jruby
http://openwferu.rubyforge.org/rdoc/classes/OpenWFE/Scheduler.html

On Wed, 2008-12-10 at 13:25 -0600, Tom E Purl wrote:

clunky. I was hoping there was something a bit more Ruby-ish. Is
there any other class that anyone has had any luck with?

Thanks!

Tom Purl


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Julio C. [email protected] wrote on 12/10/2008 02:04:48 PM:

http://openwferu.rubyforge.org/rdoc/classes/OpenWFE/Scheduler.html
Thanks for the help Julio! I’m having a weird issue, however. Here’s
my code:

if $0 == __FILE__

     begin
         scheduler = OpenWFE::Scheduler.new
         scheduler.start

         puts "Starting timer..."
         scheduler.schedule_at(Time.now + 5) do
             raise "Timeout reached"
             # I also tried this
             # exit 1
         end

         puts "Some long-running process..."
         1.upto(10) do |i|
             puts i
             sleep 1
         end
     rescue Exception => ex
         $stderr.puts ex.message
         exit 1
     end

end

The point is to kick off a “timeout” timer and then run a long-running
process. If the timer completes before my long-running process, I would
like the script print something to STDERR and return a non-zero code to
the shell.

Here’s the results, however:

C:\Dev\Jruby\log-tailer\bin>jruby .\tail-scratch.rb
Starting timer...
Some long-running process...
1
2
3
4
5
trigger() caught exception
Timeout reached
.\tail-scratch.rb:49
E:/apps/jruby-1.1.5/lib/ruby/gems/1.8/gems/openwferu-scheduler-0.9.16.1404/lib/openwfe/util/scheduler.rb:987:in

call' E:/apps/jruby-1.1.5/lib/ruby/gems/1.8/gems/openwferu-scheduler-0.9.16.1404/lib/openwfe/util/scheduler.rb:987:in trigger’
E:/apps/jruby-1.1.5/lib/ruby/gems/1.8/gems/openwferu-scheduler-0.9.16.1404/lib/openwfe/util/scheduler.rb:833:in
trigger' :1:in initialize’6

7
8
9
10

So even though I’m raising the exception, my rescue clause isn’t being
triggered. I also just tried exiting from the “schedule_at” code block,
but got very similar results. It appears that I’m killing one thread,
but the other one keeps going.

Does anyone happen to know how I can fix this? How can I force a
shutdown once my “timeout” code block is executed?

Thanks in advance!

Tom Purl