javan / whenever

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

CRON cannot access my database? Could not find table. #844

Open jcsii98 opened 1 year ago

jcsii98 commented 1 year ago

I am trying to run a model method in my cron job with whenever.

schedule.rb : `env :PATH, ENV['PATH']

set :output, "./cron.log"

every 1.minute do runner "Stock.fetch_and_update_stock_data" end`

the model method runs perfectly fine in rails console however putting it through CRON with whenever returns the error: cron.log : bundler: failed to load command: bin/rails (bin/rails) /home/jcsii98/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/sqlite3_adapter.rb:387:intable_structure': Could not find table 'stocks' (ActiveRecord::StatementInvalid)`

Any suggestions?

nbnp11 commented 6 months ago

try to add ENV.each { |k, v| env(k, v) } to your schedule.rb (that helped me)