cantino/huginn

View on GitHub
app/jobs/agent_check_job.rb

Summary

Maintainability
A
0 mins
Test Coverage
class AgentCheckJob < ActiveJob::Base
  # Given an Agent id, load the Agent, call #check on it, and then save it with an updated `last_check_at` timestamp.
  def perform(agent_id)
    agent = Agent.find(agent_id)
    begin
      return if agent.unavailable?
      agent.check
      agent.last_check_at = Time.now
      agent.save!
    rescue => e
      agent.error "Exception during check. #{e.message}: #{e.backtrace.join("\n")}"
      raise
    end
  end
end