class Materialist::Workers::Event

Public Instance Methods

perform(event) click to toggle source
# File lib/materialist/workers/event.rb, line 9
def perform(event)
  topic = event['topic']
  action = event['type'].to_sym
  timestamp = event['t']

  materializer = Materialist::MaterializerFactory.class_from_topic(topic)
  materializer.perform(event['url'], action)

  report_latency(topic, timestamp) if timestamp
  report_stats(topic, action, :success)
rescue Exception => exception
  report_stats(topic, action, :failure)
  notice_error(exception, event)
  raise
end

Private Instance Methods

notice_error(exception, event) click to toggle source
# File lib/materialist/workers/event.rb, line 43
def notice_error(exception, event)
  return unless handler = Materialist.configuration.notice_error
  handler.call(exception, event)
end
report_latency(topic, timestamp) click to toggle source
# File lib/materialist/workers/event.rb, line 27
def report_latency(topic, timestamp)
  t = (Time.now.to_f - (timestamp.to_i / 1e3)).round(1)
  Materialist.configuration.metrics_client.histogram(
    "materialist.event_latency",
    t,
    tags: ["topic:#{topic}"]
  )
end
report_stats(topic, action, kind) click to toggle source
# File lib/materialist/workers/event.rb, line 36
def report_stats(topic, action, kind)
  Materialist.configuration.metrics_client.increment(
    "materialist.event_worker.#{kind}",
    tags: ["action:#{action}", "topic:#{topic}"]
  )
end