title: Whenever gem 'failed to load command: rake'
body: <p>looking for some help.</p>
  
  <p>I am running a rails app (v3.2.5) with the <code>whenever</code> gem (v0.9.7) and <code>rake</code> (v11.2.2). I am also doing this in a docker container image <code>ruby:2.3</code> (<code>cron</code> was installed and <code>bundle install</code> was ran)</p>
  
  <p>Here is my <code>schedule.rb</code></p>
  
  <pre><code>set :environment, ENV['RAILS_ENV']
  
  every '*/2 9,10,11,12,13,14,15,16 * * 1-5' do
      rake "import_csv", output: {:error =&gt; 'log/import_csv_errors.log', :standard =&gt; 'log/import_csv.log'}'
  end
  </code></pre>
  
  <p><em>note</em> <code>RAILS_ENV</code> is set at container launch to <code>development</code></p>
  
  <p>Here is my cron job that is on the container after build (<code>crontab -l</code>):</p>
  
  <pre><code># Begin Whenever generated tasks for: /usr/src/app/config/schedule.rb
  */2 9,10,11,12,13,14,15,16 * * 1-5 /bin/bash -l -c 'cd /usr/src/app &amp;&amp; RAILS_ENV=development bundle exec rake import_csv --silent &gt;&gt; log/import_csv.log 2&gt;&gt; log/import_csv_errors.log'
  
  # End Whenever generated tasks for: /usr/src/app/config/schedule.rb
  </code></pre>
  
  <p>When this cron job runs, the logs return:</p>
  
  <p><strong>import_csv_errors.log</strong></p>
  
  <pre><code>Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `&lt;top (required)&gt;'
    /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  </code></pre>
  
  <p><strong>import_csv.log</strong></p>
  
  <pre><code>bundler: failed to load command: rake (/usr/local/bin/rake)
  </code></pre>
  
  <p>Now here is the odd thing. If I copy the cron job command: </p>
  
  <pre><code>/bin/bash -l -c 'cd /usr/src/app &amp;&amp; RAILS_ENV=development bundle exec rake import_csv --silent &gt;&gt; log/import_csv.log 2&gt;&gt; log/import_csv_errors.log'
  </code></pre>
  
  <p>and run this in the container, it works fine, but if the cron job runs it, I get thos errors in the logs!!! I am at a lost here...</p>
  
  <p>I've tried adding </p>
  
  <pre><code>env :PATH, ENV['PATH']
  env :GEM_PATH, '/usr/local/bundle'
  </code></pre>
  
  <p>to the top of <code>schedule.rb</code> and I tried doing</p>
  
  <pre><code>command 'cd /usr/src/app &amp;&amp; RAILS_ENV=development bundle exec rake import_csv --silent &gt;&gt; log/import_csv.log 2&gt;&gt; log/import_csv_errors.log'
  </code></pre>
  
  <p>Instead of using <code>rake</code> in the task and I get the same errors..</p>
  
  <p>Any help is appriciated</p>