I do this _a lot_ in myelinate. Basically can use the
./scripts/runner class to eval a simple ruby statement. The first
thing it does is to require the environment.rb, which is all you
really need to do to load up everything, set up active* etc. Just
make sure that you set your RAILS_ENV correctly.
I''ve got code in Agent.rb[1] to fork off stuff as a daemon, write
stdout to a log file, restart if necessary, etc. if you''re interested
in that, otherwise you can just let the thing run and die.
The idea behind Agent, btw, is that you''ll configure it using
./script/console by running Agent.configure( Class ) and it''ll prompt
you for everything and then save itself in the databse. Then you can
do ./script/runner ''Agent.start( "name_you_chose" )''
from cron and off
it''ll go in a rails environment. The daemon flag is currently
ignored, but that''s easy to fix.
-w
1. http://myelinate.com/svn/myelinate/trunk/app/models/agents/agent.rb
On Apr 5, 2005 5:53 PM, Rick Olson
<technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Apr 5, 2005 4:48 PM, Steve V
<ruby-ChEX1j9zMF7JbC0vcoRRxNBPR1lH4CV8@public.gmane.org> wrote:
> > Is it possible to use the models created for a rails outside of a web
app? I
> > am in the process of building a system that requires a web front end,
but
> > also a standalone server daemon, and various helper utilities. Can the
> > ActiveRecord models be used in console applications? If so, is it just
a
> > straight drop in, or is there some configuration required?
>
> Look at the script/console script. You can access the models from the
> command line with ''ruby script console development''
(substitute
> development for your environment of choice).
>
> There''s another script for handling simple 1 line statements for
cron
> jobs and such, but I can''t recall what it is.
>
> --
> rick
> http://techno-weenie.net
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Will Schenk
http://www.sublimeguile.com
http://www.myelinate.com