agent_receive_job.rb 578 B

12345678910111213141516
  1. class AgentReceiveJob < ActiveJob::Base
  2. # Given an Agent id and an array of Event ids, load the Agent, call #receive on it with the Event objects, and then
  3. # save it with an updated `last_receive_at` timestamp.
  4. def perform(agent_id, event_ids)
  5. agent = Agent.find(agent_id)
  6. begin
  7. return if agent.unavailable?
  8. agent.receive(Event.where(:id => event_ids).order(:id))
  9. agent.last_receive_at = Time.now
  10. agent.save!
  11. rescue => e
  12. agent.error "Exception during receive. #{e.message}: #{e.backtrace.join("\n")}"
  13. raise
  14. end
  15. end
  16. end