Rails comes with a script/runner script that can be used to run the code in your Rails app. There’re many ways to organize your code to let this runner script execute it, but one obvious way is to write the code as a model’s action.
Here are quick steps for doing this:
1. Insert the code into an action of a model,
(E.g) Model.MyFunction, “MyFunction” must be defined as class method, “def self.MyFunction…”
2. In your cron job, add a line to run this at certain interval:
/usr/local/bin/ruby /path/to/your/app/script/runner -e production “Model.MyFunction”
You may need to change the ruby path on your system if it is different.
