class CheckGatewayHealthJob < ApplicationJob queue_as :default def perform # Mark gateways as offline if no heartbeat in last 2 minutes offline_count = Gateway.where("last_heartbeat_at < ?", 2.minutes.ago) .where.not(status: "offline") .update_all(status: "offline") if offline_count > 0 Rails.logger.warn("Marked #{offline_count} gateways as offline due to missing heartbeat") end end end