javan / javan/whenever

Cron Jobs stopped working... Not quite sure why

Open
#646 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

awaiting-feedback ruby-version-manager-mess usage-question
Dominant language
Ruby
Stars
8.9k
Forks
715
PR merge metrics
No merged PRs in 30d

Description

Hello, i had been using the gem without issue for weeks but all the sudden the cron jobs stopped working. I knew right away because the jobs send emails upon completion. Nothing major has changed on the app so i am really unsure what could be the problem. I have tried to specify the PATH in my schedule.rb file as reported by other users with the same issues but it did not fix my problem.

This is what i have in my schedule.rb

every 5.minutes do
    runner "BankPaymentWorker.dated_transaction_reconciliation", :environment => 'development'
end

And this translates to the following when i pull a crontab - l

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /home/db1/reap && bundle exec bin/rails runner -e development '\''BankPaymentWorker.dated_transaction_reconciliation'\'' >> /home/db1/reap/cron_log.log 2>&1'

If i execute the following from the terminal it works fine: /bin/bash -l -c 'cd /home/db1/reap && bundle exec bin/rails runner -e development '\''BankPaymentWorker.dated_transaction_reconciliation'\'' >> /home/db1/reap/cron_log.log 2>&1

But when called from the cron job it does not work. The most irritating part is that i don't get a particular error message in my cron_log.log

I know the cron job uses a different environment and paths from the user that executes in the terminal but i can't seem to find a way to force the correct environment to the cron job.

One hint that things are different is what is a warning i am getting in the cron_log.log when the call is made from the Cron Job. (Not working)

/home/db1/.rvm/gems/ruby-2.2.1@global/gems/bundler-1.8.4/lib/bundler/shared_helpers.rb:83: warning: Insecure world writable dir /home/db1/reap in PATH, mode 040777

Versus the same warning when the call is made from the terminal (Working)

/home/db1/reap/vendor/cache/ruby/2.2.0/gems/spring-1.7.1/lib/spring/application.rb:175: warning: Insecure world writable dir /home/db1/reap in PATH, mode 040777
Running via Spring preloader in process 8360

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 the schedule.rb entry and compare the generated crontab line with the working manual /bin/bash -l invocation. Inspect cron_log.log, including the differing Bundler and Spring warnings, and verify the cron process environment and permissions for /home/db1/reap. Done means identifying a reproducible cause and documenting a confirmed fix for the scheduled Rails runner.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
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.