javan / whenever

Cron jobs in Ruby
MIT License
8.83k stars 728 forks source link

Whenever not working with RVM #714

Open apellizzn opened 7 years ago

apellizzn commented 7 years ago

I'am trying to run a simple cron task in my local machine. My schedule.rb is the following

set :output, 'log/cron_log.log'

every 1.minutes do
  rake 'tris:export:users'
end

By executing whenever --update-crontab --set environment=development

The cron output results in

# Begin Whenever generated tasks for: /Users/apellizz/development/four_gifters/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /Users/apellizz/development/fg && RAILS_ENV=development bundle exec rake tris:export:users --silent >> log/cron_log.log 2>&1'

# End Whenever generated tasks for: /Users/apellizz/development/fg/config/schedule.rb

and the cron_log.log says

/bin/bash: bundle: command not found

After looking for a solution i found that RVM may cause some issues so i've updated my schedule.rb like

ENV.each { |k, v| env(k, v) }
set :output, 'log/cron_log.log'

every 1.minutes do
  rake 'tris:export:users'
end

But now the log output is

Rails 5 requires Ruby 2.2.2 or newer.

    You're running
      ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

    Please upgrade to Ruby 2.2.2 or newer to continue.

Even if the rvm current output in my project folder is ruby-2.4.0.

Any suggestions?

k4m1113 commented 6 years ago

I had to work around this by manually setting the path environment variables at the top of the schedule file instead of your ENV.each loop, particularly with my :PATH variable:

env :PATH, ENV['PATH']

In lib/whenever/setup.rb line 5 it states that:

Path defaults to the directory whenever was run from

I spent countless hours figuring this out for my project. If there is a better solution I would be glad to make a PR.

mijailr commented 6 years ago

Any update with this?

mltcx commented 6 years ago

I ran into a similar problem and fixed it by declaring the :whenever_path inside deploy.rb set :whenever_path, -> { release_path }