Forum: JRuby Timer Alternatives

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
22db9ef38f6c2301ef7fd667f18874d2?d=identicon&s=25 Tom E Purl (Guest)
on 2008-12-10 20:27
(Received via mailing list)
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
9dc24638923a6aee9fd3571c14f01066?d=identicon&s=25 Julio Capote (jcapote)
on 2008-12-10 21:07
(Received via mailing list)
I've had success with this in the past in jruby
http://openwferu.rubyforge.org/rdoc/classes/OpenWF...

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
22db9ef38f6c2301ef7fd667f18874d2?d=identicon&s=25 Tom E Purl (Guest)
on 2008-12-11 16:32
(Received via mailing list)
Julio Capote <jcapote@gmail.com> wrote on 12/10/2008 02:04:48 PM:
> http://openwferu.rubyforge.org/rdoc/classes/OpenWF...
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
This topic is locked and can not be replied to.