Problem with cron job

Showing 1-13 of 13 messages
Problem with cron job mathias 7/18/11 2:27 AM
Hi

I do this:

> require "rufus/scheduler"
> s = Rufus::Scheduler.start_new
> j = s.cron("* * * * *") do
>      puts "*** Executing #{Time.now}"
> end

expecting the execution of the puts statement every minute.

> j.next_time

correctly prints out the expected time of next execution at any
point., however, the actual execution NEVER happens.

I am on

ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

and have tried Rufus 2.0.7 and 2.0.10 with the same issue.

Any help appreciated...

Thanks

Mathias
Re: [rufus:660] Problem with cron job John Mettraux 7/18/11 5:48 AM

On Mon, Jul 18, 2011 at 02:27:21AM -0700, mathias wrote:
>
> > require "rufus/scheduler"
> > s = Rufus::Scheduler.start_new
> > j = s.cron("* * * * *") do
> >      puts "*** Executing #{Time.now}"
> > end
>
> expecting the execution of the puts statement every minute.
>
> (...)

>
> the actual execution NEVER happens.
>
> I am on ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
> and have tried Rufus 2.0.7 and 2.0.10 with the same issue.

Hello Mathias,

sorry for the late reply.

Please do

---8<---


require "rufus/scheduler"
s = Rufus::Scheduler.start_new
j = s.cron("* * * * *") do
     puts "*** Executing #{Time.now}"
end
s.join
--->8---

so that the Ruby runtime doesn't exit (let it join the scheduler thread).


Best regards,

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

Re: Problem with cron job mathias 7/20/11 2:24 AM
Hi John

thanks for your reply. It works with the join, but I should have
mentioned that I am executing everything in irb (or in my Rails app)
so I would have thought the join would not be necessary. Because if I
join the main thread in my Rails app it will obviously block forever
on the scheduler. Or do I have to fork an extra thread myself for the
scheduler? Seems I have a conceptual misunderstanding here on how
Rufus works...

Thanks for any additional help on this!

Mathias
Re: [rufus:662] Re: Problem with cron job John Mettraux 7/20/11 2:43 AM

On Wed, Jul 20, 2011 at 02:24:08AM -0700, mathias wrote:
>
> thanks for your reply. It works with the join, but I should have
> mentioned that I am executing everything in irb (or in my Rails app)
> so I would have thought the join would not be necessary.

Hello Mathias,

Yes, you are right, the join is not necessary in those two cases. Well, rufus-scheduler will be "alive" as long at the Ruby process behind irb or Rails is running.

> Because if I
> join the main thread in my Rails app it will obviously block forever
> on the scheduler. Or do I have to fork an extra thread myself for the
> scheduler? Seems I have a conceptual misunderstanding here on how
> Rufus works...

The scheduler will use 1 thread for its work. Starting the scheduler creates that thread.

You don't have to "join" as long as the HTTP request handling loop is alive and prevents the Ruby process from terminating.

There is no magic.


Best regards,

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

Re: Problem with cron job mathias 7/21/11 2:29 AM
Hi John

ok, but then I'm back to my original problem. In irb, the following
does not trigger the job every minute as I would expect:

> require "rufus/scheduler"
> s = Rufus::Scheduler.start_new
> j = s.cron("* * * * *") do
>      puts "*** Executing #{Time.now}"
> end

However, if I call the join in irb, it works, but blocks my main
thread:

> require "rufus/scheduler"
> s = Rufus::Scheduler.start_new
> j = s.cron("* * * * *") do
>      puts "*** Executing #{Time.now}"
> end
> s.join

Same in Rails...

Thanks

Mathias
Re: [rufus:664] Re: Problem with cron job John Mettraux 7/21/11 3:22 AM

On Thu, Jul 21, 2011 at 02:29:09AM -0700, mathias wrote:
>
> ok, but then I'm back to my original problem. In irb, the following
> does not trigger the job every minute as I would expect:
>
> > require "rufus/scheduler"
> > s = Rufus::Scheduler.start_new
> > j = s.cron("* * * * *") do
> >      puts "*** Executing #{Time.now}"
> > end
>
> However, if I call the join in irb, it works, but blocks my main
> thread.

Of course, it's useless to have to call #join when in irb.

Try the following experiment in your irb :

  > Thread.new { sleep 1; puts "nada" }

And then wait two seconds, then do :

  > puts "ok"

...

> Same in Rails...

Probably not linked to the "issue" you're seeing in irb.

What web server are you running Rails with ? Webrick, Thin, Passenger ?


Best regards,

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

Re: Problem with cron job mathias 7/22/11 2:41 AM
Done the experiment...point taken. I have tried this in irb:

> class JobThing
>
>   attr_reader a:
>
>   def initialize
>      @a = []
>   end
>
>   def call(param)
>      @a << Time.now
>   end
>
> end
>
> m = JobThing.new
> s = Rufus::Scheduler.start_new
> j = s.cron( "* * * * *", m )

...but after a few minutes, m still has not changed (@a should be an
array with a timestamp for each minute's execution of m)

> m.a
=> []

This should work in irb or in any other execution environment, right?



Many thanks for your help

Mathias
Re: [rufus:666] Re: Problem with cron job John Mettraux 7/22/11 3:02 AM

On Fri, Jul 22, 2011 at 02:41:50AM -0700, mathias wrote:
>
> I have tried this in irb:
>
> > class JobThing
> >
> >   attr_reader a:
> >
> >   def initialize
> >      @a = []
> >   end
> >
> >   def call(param)
> >      @a << Time.now
> >   end
> >
> > end
> >
> > m = JobThing.new
> > s = Rufus::Scheduler.start_new
> > j = s.cron( "* * * * *", m )
>
> ...but after a few minutes, m still has not changed (@a should be an
> array with a timestamp for each minute's execution of m)
>
> > m.a
> => []
>
> This should work in irb or in any other execution environment, right?

Hello,

yes it should work. I had never tried from irb.

  https://github.com/jmettraux/rufus-scheduler/issues/22


Thanks for the feedback, best regards,

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

Re: Problem with cron job mathias 7/25/11 3:26 AM
Thanks. I believe it does not work in Rails (I'm using thin web server
with Rails) either...
Re: [rufus:671] Re: Problem with cron job John Mettraux 7/25/11 3:34 AM

On Mon, Jul 25, 2011 at 03:26:42AM -0700, mathias wrote:
>
> Thanks. I believe it does not work in Rails (I'm using thin web server
> with Rails) either...

Hello Mathias,

"believing" is for the church or whatever worship bikeshed you go to (don't tell me you're a Jedi Knight, I don't want to know).

  http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Since 2007, I've helped various people integrate rufus-scheduler within their rails application, so "it does not work in Rails either", I don't believe it either.

I'm OK with it not working in IRB, since not many people schedule stuff from IRB, manually, so it might have gone unnoticed all this time, but not for the Rails issue you believe in.


Best regards,

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

Re: Problem with cron job mathias 7/25/11 10:57 AM
Hi John

was giving you an observation, not a critique on your work.
Disappointed to see the reaction I have provoced, but maybe the author
is as immature as the product...

Thanks

Mathias
Re: [rufus:673] Re: Problem with cron job KJ 7/25/11 11:04 AM
Dear Mathias,

I am sure John can fend for himself but I have to support John on this. Given the level of (free!) support he gives you should be ashamed of yourself. Please take your disrespect elsewhere....

Regards,

Klaas Jan Wierenga

> --
> you received this message because you are subscribed to the "rufus ruby" group.
> to post : send email to rufus...@googlegroups.com
> to unsubscribe : send email to rufus-ruby+...@googlegroups.com
> more options : http://groups.google.com/group/rufus-ruby?hl=en

Re: [rufus:674] Re: Problem with cron job John Mettraux 7/25/11 5:33 PM

On Mon, Jul 25, 2011 at 08:04:35PM +0200, Klaas Jan Wierenga wrote:
> Dear Mathias,
>
> I am sure John can fend for himself but I have to support John on this. Given the level of (free!) support he gives you should be ashamed of yourself. Please take your disrespect elsewhere....
>
> Regards,
>
> Klaas Jan Wierenga
>
> Op 25 jul 2011, om 19:57 heeft mathias het volgende geschreven:
>
> > Hi John
> >
> > was giving you an observation, not a critique on your work.
> > Disappointed to see the reaction I have provoced, but maybe the author
> > is as immature as the product...


Hello Klaas,

thanks for the support and the help. Much appreciated !


Hello Mathias,

rufus-scheduler is a project, not a product.

The reaction you have provoked is simply exasperation. As already written, I've read here about people using this scheduler here and there, and suddenly you claim and come it doesn't work with Rails.

It took four days of this thread to extract the first issue report (the one about irb).

The one about "rails and thin" is more important it seems, but it's hidden behind a "belief". I got tired, I didn't want to spend another 4 days trying to extract information out of you. You seem to be sitting right in front of the issue, could you please describe it for me in details ? It would save us both time.

If you don't have the time anymore, I'd suggest you look at a similar library, it's called "clockwork":

  https://github.com/adamwiggins/clockwork

I can't say anything about this library's level of maturity. The author is a very talented guy, that I know for sure.


Sorry for my loss of temper, best regards,

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