简体   繁体   中英

Rake task failing with `source: not found` on Heroku

I have a Rails project with a rake task called update_data , which is as follows:

every 1.day, :at => '2:30 am' do
  root = File.expand_path('../..', __FILE__)
  system("""(source #{root}/data_scripts/venv/bin/activate;
             python #{root}/data_scripts/scripts/main.py;
             deactivate)""")
end

This should first activate the virtualenv, run the script, and then deactivate the virtualenv. When I run rake update_data , this works perfectly. However, when I run heroku run rake update_data , it fails with sh: 1: source: not found . What should I do so that source is available on Heroku?

The error message sh: 1: source: not found means that:

  1. you run sh instead of bash ,
  2. source is not a built-in command and the shell isn't able to find source in PATH .

To confirm this run heroku run sh , type source and compare the output with trying to execute foobar .

I recommend you try passing the command to bash (via `bash -c "your command goes here"). You may also need a Python buildpack. You can add it with:

heroku buildpacks:add heroku/python

I feel like you don't need to activate your virtualenv.

Just use the virtualenv's python executable:

every 1.day, :at => '2:30 am' do
  root = File.expand_path('../..', __FILE__)
  system("#{root}/data_scripts/venv/bin/python #{root}/data_scripts/scripts/main.py")
end

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