I’m having a strange problem. I need to open a mongrel server (with
mongrel_service and Windows) and I also need to run tasks in parallel
with mongrel. So, first I tried a Thread.new do … end in my
environment.rb. Soon I realized it would never work, because even
running tasks like rake db:migrate, rake test, my thread would run. That
was not my intention… I just need to run when I start mongrel. So, I
override the “run” method from mongrel, this way:
alias_method :original_mongrel_run, :run
$my_object = MyClass.new
My run_task method is something like this:
RAILS_DEFAULT_LOGGER.debug ‘Running task’
RAILS_DEFAULT_LOGGER.debug ‘Task Done’
rescue Exception => e
It seemed to work fine. But, sometimes, I’m having some weird problems.
Sometimes, my thread suddenly “dies” after a few hours, during the
“sleep” command. According to my log, the task isn’t stopping inside the
“do_something” method. Instead, it is stopping during my sleep time.
There’s another problem. The task is running OK for some time. But, if I
open my web browser and navigate to a single page in my app, I start to
get thousands of “stack level too deep” errors, in my rescue block! I
tried (almost) everything (at least everything I know) to solve this,
but I couldn’t figure out the problem!
Maybe I should be running this thread and these tasks in another way.