简体   繁体   中英

How can we run a rake task of one application through another application (both running on the same server)?

Issue : I have two applications A & B both running on the same server. I have a script in the filesystem

cd /data/B/
bundle exec rake -T 

When i run the script through the rails console of application A it errors as the console loads the gems of A and the rake task fails

  eg: system("sh ~/test.sh")

rake aborted!
LoadError: cannot load such file -- log4r
/home/kumolus/api/config/application.rb:9:in `require'
/home/kumolus/api/config/application.rb:9:in `<top (required)>'
/home/kumolus/api/Rakefile:1:in `require'
/home/kumolus/api/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)

When i run the script through the unix command line (irrespective of my pwd) it works

cd ~
sh test.sh  #works

cd /data/A   #my application A's dir
sh ~/test.sh   #also works

I need it to work through rails.Any help ? Thanks!

Thanks guys for your help, I found a solution its due to bundler default behaviour.

I used with_clean_env method with a block and it gets executed.

Thanks Team Cheers

I think cd'ing to the folder should be sufficient to switch the environment within the shell process which is doing the cd'ing . Try this.

Go into project B and do

which bundle

in the command line, and copy the result somewhere. Then do

which rake

and copy the result of that.

Then, switch to project A and start a rails console. Then try this:

`cd /path/to/projectB; bundle exec rake  -T`

If that doesn't work, try this:

`cd /path/to/projectB; <result of doing "which bundle" earlier> exec rake -T`

Then if it still doesn't work, try this:

`cd /path/to/projectB; <result of doing "which bundle" earlier> exec <result of doing "which rake" earlier> -T`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM