3

Our company use rails as our server, and we will rake tasks daily without monitoring. When the rake aborts, we can not get the aborting information until we find that our data is strange.

How can I get the rake-aborting infomation as soon as possible via email or through any other method?

Mat
  • 202,337
  • 40
  • 393
  • 406
  • see: http://stackoverflow.com/questions/7161374/rails-exception-notifier-in-rake-tasks – Vik Apr 24 '12 at 08:02

2 Answers2

1

You can try this gem - https://github.com/oscardelben/rake_notifier

Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77
1

If you're running your Rake task via cron, you can define the MAILTO variable (see man 5 crontab for details). This should send standard output and standard error from your cron jobs to the address defined by MAILTO.

Another common problem is that cron doesn't always set up the same environment as your normal shell, so you should either set up the proper environment inside your crontab (which will be implementation specific, and may not be possible and/or portable) or just create a shell script with all the necessary environment variables needed to run your task.

Your crontab should look something like this:

MAILTO=user@example.com

# This should work if your crontab environment knows about Ruby and Rake.
PATH=/path/to/ruby:$PATH
GEM_PATH=/path/to/gems
0 0 * * * cd /path/to/project; rake foo

# Otherwise, just create a shell script with a sane environment for running
# rake tasks, and call your rake tasks from the script.
1 0 * * * /path/to/your/script.sh
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199