Skip to content
HookPulse

Monitor Rails rake tasks with HookPulse check-ins

A scheduled rake task checks in with Net::HTTP when it ends, and reports the failure when it raises.

Updated

1Create the monitor

Add a routine named rails-backup and set how often the job runs. Its page shows the check-in URL: use it in place of https://hookpulse.net/in/YOUR_ID.

2Check in at the end of the task

Schedule the task with cron, whenever or your platform scheduler.

# lib/tasks/backup.rake
require "net/http"

namespace :backup do
  desc "Nightly backup with a HookPulse check-in"
  task run: :environment do
    check_in = ->(path = "") { Net::HTTP.get_response(URI("https://hookpulse.net/in/YOUR_ID#{path}")) }
    begin
      Backup.run!
      check_in.call
    rescue StandardError
      check_in.call("/fail")
      raise
    end
  end
end

3Run it once

Run bin/rails backup:run once. The routine shows the first check-in. From then on, a missed or failed run sends the alert.