0

I wrote a rake task which executes from command line and not from cronjob.

I wrote a task which internally calls model method, so suppose my task name is dataimport so if I call as

rake db:dataimport

it works, and create records in database. But when I want execute it for every 10 seconds I putin crontab as

* * * * * sleep 10; cd $APP_DIR/lib/tasks; rake db:dataimport

this doesn't work.Any suggestions on this.

Sonalkumar sute
  • 2,485
  • 2
  • 14
  • 26
  • *this doesn't work* any errors? trace? or something? – Philidor Jul 15 '15 at 10:50
  • Where can I see errors, as this is `cronjob`, which is executing code from rake task. errors are not getting logged in `production.log` – Sonalkumar sute Jul 15 '15 at 10:58
  • What about `grep CRON /var/log/syslog` ? Have you see something about you task? Cronjob do not post the result of job to the rails logs, you should look at system logs. – Philidor Jul 15 '15 at 11:02
  • yes done that, `Jul 15 13:03:01 app-ded-1 /USR/SBIN/CRON[13217]: (app) CMD (sleep 10; cd $APP_DIR/lib/tasks; rake db:dataimport)`, it shows something like this with many lines, no errors – Sonalkumar sute Jul 15 '15 at 11:05
  • I suggest you read [`debugging crontab`](http://stackoverflow.com/questions/4883069/debugging-crontab) this article can help you to resolve issue. – Philidor Jul 15 '15 at 11:07
  • It could be an environment issue. Do you use something like rvm or rbenv? – ihaztehcodez Jul 15 '15 at 11:29
  • @ihaztehcodez I am not using any of them, it's ruby directly – Sonalkumar sute Jul 15 '15 at 12:50

1 Answers1

0

For rake commands to execute, you need to set PATH variable in your crontab file

If you are using ubuntu linux then first execute 'crontab -e' command and then add the following line

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

at the top of the file.

scanE
  • 332
  • 4
  • 19