javan / javan/whenever

CRON cannot access my database? Could not find table.

Open
#844 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
8.9k
Forks
715
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with schedule.rb and cron.log, then compare the environment used by the cron runner with the Rails console invocation. The issue is done when Stock.fetch_and_update_stock_data runs through cron and ActiveRecord can find the stocks table.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby, sqlite
Domain
backend, database, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.