0

I am using the "whenever" gem which generated a cron line for me.

0 5 * * * /bin/bash -l -c 'cd /projects/my_rails && rails runner -e development "Indexing::LikeIndexer.index_deltas"'

(The cron above is just for testing and won't be running this frequently in production =))

This and other crons (like thinking_sphinx's) require loading the whole rails environment in order to execute the code. (Rails cron with whenever, setting the environment)

Is there any gem that runs my rails environment and allows it to execute code without having to reload the whole environment?

I attempted to solve the problem with spin but it seems that spin doesn't recognize my models when I pass a file to it.

Community
  • 1
  • 1
Abdo
  • 13,549
  • 10
  • 79
  • 98

1 Answers1

2

You realize that your example is ran every day at 5 in the morning. If you can't reload your environment once per day , you might have a bigger problem that the one you try to fix :)

About your question, the only way to not reload the environment would be for a process to stay in memory with the environment loaded and then fork itself for doing the job. That's the idea behind spork for speeding up tests.

I think it's a bit overpowered for your problem.

You could also make a rake task not depending on environment for doing your job or make a controller action and cron a curl command (with some kind of authentication mechanism of course)

systho
  • 1,161
  • 7
  • 17