Problem with cron job

458 views
Skip to first unread message

mathias

unread,
Jul 18, 2011, 5:27:21 AM7/18/11
to Rufus Ruby
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

John Mettraux

unread,
Jul 18, 2011, 8:48:17 AM7/18/11
to rufus...@googlegroups.com

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

mathias

unread,
Jul 20, 2011, 5:24:08 AM7/20/11
to Rufus Ruby
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

John Mettraux

unread,
Jul 20, 2011, 5:43:06 AM7/20/11
to rufus...@googlegroups.com

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.

mathias

unread,
Jul 21, 2011, 5:29:09 AM7/21/11
to Rufus Ruby
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

John Mettraux

unread,
Jul 21, 2011, 6:22:33 AM7/21/11
to rufus...@googlegroups.com

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 ?

mathias

unread,
Jul 22, 2011, 5:41:50 AM7/22/11
to Rufus Ruby
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

John Mettraux

unread,
Jul 22, 2011, 6:02:18 AM7/22/11
to rufus...@googlegroups.com

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,

mathias

unread,
Jul 25, 2011, 6:26:42 AM7/25/11
to Rufus Ruby
Thanks. I believe it does not work in Rails (I'm using thin web server
with Rails) either...

John Mettraux

unread,
Jul 25, 2011, 6:34:16 AM7/25/11
to rufus...@googlegroups.com

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,

mathias

unread,
Jul 25, 2011, 1:57:59 PM7/25/11
to Rufus Ruby
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

Klaas Jan Wierenga

unread,
Jul 25, 2011, 2:04:35 PM7/25/11
to rufus...@googlegroups.com
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

John Mettraux

unread,
Jul 25, 2011, 8:33:39 PM7/25/11
to rufus...@googlegroups.com

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,

Reply all
Reply to author
Forward
0 new messages