<commit_before>require "librato-rack"

module Robin
  module Sidekiq
    ##
    # Sidekiq server middleware for measuring Sidekiq stats
    class QueueStats < Base
      ##
      # Sends Sidekiq metrics to Librato then yields
      #
      # @param [Sidekiq::Worker] worker
      #   The worker the job belongs to.
      #
      # @param [Hash] _msg
      #   The job message.
      #
      # @param [String] queue
      #   The current queue.
      def call(worker, _msg, queue)
        Librato.measure "#{namespace}.retries", retries.size
        Librato.measure "#{namespace}.scheduled", scheduled.size
        Librato.increment "#{namespace}.processed"

        # queue specific
        sidekiq_queue = ::Sidekiq::Queue.new(queue)
        queue_namespace = metrics.for(queue: queue)
        Librato.measure "#{queue_namespace}.size", sidekiq_queue.size
        Librato.measure "#{queue_namespace}.latency", sidekiq_queue.latency
        Librato.increment "#{queue_namespace}.processed"

        yield if block_given?
      rescue => e
        Librato.increment "#{namespace}.failed"
        Librato.increment "#{queue_namespace}.failed"
        raise e
      end

      private

      def retries
        @_retries ||= ::Sidekiq::RetrySet.new
      end

      def scheduled
        @_scheduled ||= ::Sidekiq::ScheduledSet.new
      end<commit_msg>A block is always given<commit_after>require "librato-rack"

module Robin
  module Sidekiq
    ##
    # Sidekiq server middleware for measuring Sidekiq stats
    class QueueStats < Base
      ##
      # Sends Sidekiq metrics to Librato then yields
      #
      # @param [Sidekiq::Worker] worker
      #   The worker the job belongs to.
      #
      # @param [Hash] _msg
      #   The job message.
      #
      # @param [String] queue
      #   The current queue.
      def call(worker, _msg, queue)
        Librato.measure "#{namespace}.retries", retries.size
        Librato.measure "#{namespace}.scheduled", scheduled.size
        Librato.increment "#{namespace}.processed"

        # queue specific
        sidekiq_queue = ::Sidekiq::Queue.new(queue)
        queue_namespace = metrics.for(queue: queue)
        Librato.measure "#{queue_namespace}.size", sidekiq_queue.size
        Librato.measure "#{queue_namespace}.latency", sidekiq_queue.latency
        Librato.increment "#{queue_namespace}.processed"

        yield
      rescue => e
        Librato.increment "#{namespace}.failed"
        Librato.increment "#{queue_namespace}.failed"
        raise e
      end

      private

      def retries
        @_retries ||= ::Sidekiq::RetrySet.new
      end

      def scheduled
        @_scheduled ||= ::Sidekiq::ScheduledSet.new
      end
{'fraction_non_alphanumeric': 0.10274480712166172, 'fraction_numerical': 0.0, 'mean_word_length': 2.350310559006211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3845839', 'n_tokens_mistral': 821, 'n_tokens_neox': 807, 'n_words': 189}