alpaca
alpaca

Reputation: 1231

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?

Upvotes: 0

Views: 212

Answers (2)

Greg Navis
Greg Navis

Reputation: 2934

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

Upvotes: 2

Denis Olehov
Denis Olehov

Reputation: 192

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

Upvotes: 0

Related Questions