Monitor Ruby Rake Tasks with CronRabbit
RubyThe 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
Rubyrequire '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