Monitor Ruby Rake Tasks with CronRabbit

Ruby

The Problem

Rake tasks invoked by cron can fail due to missing dependencies, database issues, or environment configuration problems.

The Solution

Add CronRabbit pings at the beginning and end of your Rake task blocks.

Rake Task Pattern

Wrap your task logic with start/success/fail pings. Use rescue to catch exceptions and report failures.

Code Examples

Monitored Rake task

Ruby
require 'net/http'

namespace :maintenance do
  desc "Clean up expired sessions"
  task cleanup: :environment do
    ping_url = "https://ping.cronrabbit.com/your-id"
    Net::HTTP.get(URI("#{ping_url}/start")) rescue nil
    begin
      Session.expired.delete_all
      TempFile.older_than(7.days).destroy_all
      Net::HTTP.get(URI(ping_url)) rescue nil
    rescue => e
      Net::HTTP.get(URI("#{ping_url}/fail")) rescue nil
      raise
    end
  end
end

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.