javan/whenever

CRON cannot access my database? Could not find table.

jcsii98 opened this issue · 1 comments

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:in table_structure': Could not find table 'stocks' (ActiveRecord::StatementInvalid)`

Any suggestions?

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