views:

32

answers:

3

Is there a way to run processes from rails script/console in the background? I have a onetime lib script that will take two or so days to execute and I want to set this to run in the background.

Something like:

script/console

Then:

>> load 'script.rb' &

In the commandline I'd just do:

$ command &

I did find: http://backgroundrb.rubyforge.org/ but this seemed like overkill for just this onetime task.

I also tried:

$ ruby data_importer2.rb &

This doesn't import the active record stuff though (error: uninitialized constant ActiveRecord)

Thanks!

+5  A: 

You can do this with the script runner instead of the console:

./script/runner script.rb &
jdeseno
+2  A: 

You could use script/runner, or if you need to run it again at some point, the easiest way would be to wrap it in a rake task.

daryn
+2  A: 
$ script/console
>> fork { load 'script.rb' }
>> Process.detach
>> # ...
Adrian