Sha256: 44d457063c3e14cbb62512835b5ae98b9d00c6132850bbb2c1c928e2cd181fa3

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'sidekiq'
require_relative '../materializer_factory'

module Materialist
  module Workers
      class Event
      include Sidekiq::Worker

      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
        report_stats(topic, action, :failure)
        raise
      end

      private

      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

      def report_stats(topic, action, kind)
        Materialist.configuration.metrics_client.increment(
          "materialist.event_worker.#{kind}",
          tags: ["action:#{action}", "topic:#{topic}"]
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
materialist-3.2.0 lib/materialist/workers/event.rb
materialist-3.1.0 lib/materialist/workers/event.rb