Hello,
sorry for the late reply, I was travelling.
Are you telling me that previously you were not using the -d option ?
--
John Mettraux - http://lambda.io/processi
Hello,
what about trying something like
---8<---
loop do
p Time.now
Notifier.send_test.deliver
sleep 2 * 60
end
--->8---
to see if it's really a rufus-scheduler issue ?
Best regards,
Hello,
I don't understand this paragraph. Could you please rephrase it (with more details as I haven't used mongrel in while) ?
Thanks in advance,
What do you mean by "never executed" ? Do you mean that the initializer code where the scheduler is initialized is never interpreted ?
"the task is never executed and therefore it never runs" what's the difference between to execute and to run ?
> However, it does run, if I execute the following:
>
> rails server -e production -p 8000
>
> The number of threads is 3, according to the output of ps aux -L
In which case -d or no -d ?
> Mongrel is booted just after starting the rails server, and I have
> not changed any specific configuration in Mongrel, apart from the port
> it listens to.
I don't understand the "mongrel is booted after the rails server" part.
Have you try using mongrel_rails [-d] like explained in
https://github.com/fauna/mongrel
?
Best regards,
So if I understand correctly this code is not interpreted. Where did you place it ? In config/initializers/ ?
If in /config/initializers/ the next question is: are the other initializers not run as well when -d is used ?
Thanks in advance,
Hello,
try putting a puts "in" in config/initializers/whatever_the_name.rb before the scheduler instantation and a puts "out" after the scheduler instantiation. This would tell us if the initialization code gets executed or not (if "in" and "out" somehow appear in some log, then the scheduler initialization code got executed and we're left determining why it doesn't trigger).
Try also with Thread.abort_on_exception = true, it might yield something interesting in some log.
> Another thing I realised is that using -d only 3 threads are used as I
> stated, but not using -d 4 threads are running, I assume the fourth
> thread is the one from the scheduler...
That's an excellent piece of information. Would those three threads be mongrel workers ? Maybe some googling would help.
By the way, you haven't told me what happened when starting with mongrel_rails instead of rails.
I will try spending an hour setting up a test environment similar to yours and running tests by myself.
Best regards,
James,
by the way, which patch level of Ruby 1.9.2 are you using ? 290 ?
Thanks in advance,
OK, whatever, trying with 290 on Ubuntu 11.04 (sorry I have not 10.04 around).
I've created this mini-project
https://github.com/jmettraux/james_lopez
Sticking to, hopefully, the versions you indicated to me:
https://github.com/jmettraux/james_lopez/blob/master/Gemfile
My initializer looks like:
https://github.com/jmettraux/james_lopez/blob/master/config/initializers/scheduler.rb
Please note that I'm trying both with a thread and both with rufus-scheduler.
The result ? It works without -d, it doesn't work with -d.
I have observed, like you did that the number of [green] threads per process is one less for -d. But I had 5 threads for -d.
I decided to look a bit deeper and came up with this controller:
https://github.com/jmettraux/james_lopez/blob/master/app/controllers/status_controller.rb
I curled it for normal operations:
https://github.com/jmettraux/james_lopez/blob/master/out/status_non_d.txt
and for backgrounded operations:
https://github.com/jmettraux/james_lopez/blob/master/out/status_d.txt
The threads seem to be present.
So the initializer is executed, contradicting your affirmation:
> Yes, I mean that the following peace of code inside the initialiser is
> never interpreted:
>
> scheduler = Rufus::Scheduler.start_new
> scheduler.in("50s") do
> Rails.logger.info "test"
> end
Now why the thread seem not to run... I don't know. If I were you, I'd dig in the mongrel documentation. I'm sure you're not the first one to have that issue.
I could tell you to use Thin or another server, but you already told me you're stuck with Mongrel. Maybe you could try with Mongrel 1.1.5 (the stable release according to https://rubygems.org/search?utf8=%E2%9C%93&query=mongrel)
I've tried googling for things like "mongrel initializer thread" but had no success, it seems all centered on Rails and thread-safety.
I don't think I'll take the time to investigate that further.
Maybe you could try Clockwork (https://github.com/adamwiggins/clockwork), but it also uses a thread like rufus-scheduler. So as long as threads in an initializer seem to get lost, it's probably not going to work.
All the best.