The delayed_job_tracer gem is designed to monitor the delayed_job gem, which was extracted from Shopify (http://github.com/tobi/delayed_job), but is now maintained at (https://github.com/collectiveidea/delayed_job). It will alert you via e-mail if something goes wrong, such as if the delayed_job process crashes or one of its jobs fails or takes too long to complete.
This gem also detects wither e-mails sent through delayed_job are actually being delivered by sending test messages (like tracer bullets) to an e-mail account then checking that account to ensure they were processed and dispatched via the delayed_job queue. The e-mail delivery detection allows you to be notified if e-mails can’t be sent out either because of delayed_job having choked or because of an issue with the e-mail account the application uses to send e-mail.
- Sends an e-mail notification when delayed_job crashes or is unable to complete a job in a reasonable amount of time.
- Sends an e-mail notification when the Rails application is unable to successfully deliver e-mails via delayed_job.
- Circumvents the need for a process monitoring tool like Monit or God for delayed_job processes.
- Keeps memory usage low by working outside of Rails.
Why use a Cron’d ruby process to monitor delayed_job and e-mail delivery?
- Cron is often considered to be more reliable than process monitoring tools like Monit or God.
- The Cron’d Ruby process only uses a modest amount of memory (~27MB) for a few seconds at regular intervals, whereas a rake task or runner would equate to the entire size of the Rails application, with a memory footprint that grows over time.
Why use a Perl Script to send alert e-mails to admins?
- It’s fast
- It doesn’t rely on the Rails application
- It doesn’t rely on the delayed_job process you’re monitoring with this gem
1) Install XML and SSL Packages:
Note: These are for Ubuntu. You may need to find alternate packages for your platform.
sudo apt-get install libxml2-dev libxslt-dev libnet-ssleay-perl libcrypt-ssleay-perl libio-socket-ssl-perl
2) sendEmail Perl script:
Download from http://caspian.dotconf.net/menu/Software/SendEmail and follow the setup instructions, or just follow these instructions:
wget -c http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz tar xvfz sendEmail-v1.56.tar.gz sudo cp -a sendEmail-v1.56/sendEmail /usr/local/bin chmod +x /usr/local/bin/sendEmail
Run it to be sure it works:
rm -rf sendEmail-v1.56*
1) Add the gem to your Gemfile:
2) Generate the config file:
rails g delayed_job_tracer
- Create a ‘DelayedJobTracer’ folder/label in the e-mail account you configure the plugin to send test messages to and a filter to move all incoming messages with ‘[DelayedJobTracer]’ in the subject line to this folder (or label if you’re using Gmail). Set the name of this folder in the config/delayed_job_tracer_config.yml file – as it will be the folder that the Ruby process checks for test messages.
- Add a Cron job on the server:
Example for running every 15 minutes, replace with your actual app and ruby locations:
*/15 * * * * /usr/local/bin/delayed_job_tracer -c /opt/apps/appname/current/config/delayed_job_tracer_config.yml
- Finish configuring your settings in the config/delayed_job_tracer_config.yml file. Your database and ActionMailer config will be applied via the generator, but you’ll still need to provide an alternate e-mail account to send administrative notifications through, provide the admin’s e-mail address and so forth.
The MIT License
Copyright © 2010-2011 Kenny Johnston
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN