Place for special scripts in the framework?

If you just want to manually run this, or run it from cron, you can use /script/runner and pass it the path to a script. It will execute the script within the rails environment so everything will be available to you. The script can be really simple if the methods are already defined in models or libraries. like:

In a model:

class Foo < ActiveRecord::Base     def self.do_long_foo_thing        do_something_long     end end

Then in a script /tmp/my_script:

Foo.do_long_foo_thing

then /path/to/rails/app/script/runner /tmp/my_script

I created a site_scripts directory under my scripts directory to hold these, but you can put them wherever. I use them for cleaning sessions and various other tasks.

However, if this is something that needs to be initiated from a web page, but you want to background it, check out BackgroundDRB http://backgroundrb.rubyforge.org/.

Hope this helps.

Sy Ys wrote:

If you just want to manually run this, or run it from cron, you can use /script/runner and pass it the path to a script. It will execute the script within the rails environment so everything will be available to you. The script can be really simple if the methods are already defined in models or libraries. like:

In a model:

class Foo < ActiveRecord::Base    def self.do_long_foo_thing       do_something_long    end end

Then in a script /tmp/my_script:

Foo.do_long_foo_thing

If that's all you're doing there's no reason to make /tmp/my_script. Just do like this:

script/runner 'Foo.do_long_foo_thing'

Exactly, I just assumed he had more to do than that. I was simply demonstrating that most of the time the script needs not includes, etc. This was obviously an example.

Philip Hallstrom wrote: