<commit_before>module Hightops
  # Public: Mixin module for worker classes.
  #
  # Example:
  #
  #   class SomeWorker
  #     include Hightops::Worker
  #
  #     subscribe_to_inter_service_event :upload, events: [:created]
  #   end
  #
  # Workers can be used in two different ways, namely inter-service event
  # processing and intra-service background job processing. Names of AMQP
  # components used for events are determined by project configuration.
  module Worker
    # Public: Error indicating missing implementation of #perform method
    class NotImplemented < StandardError; end

    def self.included(base)
      base.send(:include, Sneakers::Worker)
      base.send(:include, InstanceMethods)
      base.extend ClassMethods
    end

    module InstanceMethods
      # Internal: Parse JSON payload as preprocessing to perform desired
      # task for the worker and send acknowledgement.
      #
      # payload - The String of JSON payload.
      #
      # Returns nothing.
      def work(payload)
        perform HashWithIndifferentAccess.new(MultiJson.load(payload))

        ack!
      end

      # Public: After being overriden, performs desired task for the worker.
      #
      # arguments - The Hash containing arguments in concern.
      #
      # Returns nothing.
      def perform(arguments = {})
        raise Hightops::Worker::NotImplemented.new
      end
    end

    module ClassMethods
      # Public: Subscribe to inter-service event through shared exchange.
      # Name of the queue is automatically determined by name of the worker
      # class.
      #
      # tag    - The Symbol tag name of exchange to be subscribed.
      # events - The Array of event types to subscribe to.
      #
      # Returns nothing.
      def subscribe_to_inter_service_event(tag, options = {})
        exchange_naming = Hightops::Naming::SharedExchange.new(tag: tag)
        events = options[:events] || ['#']

        from_queue naming.to_s, options.merge(exchange: exchange_naming.to_s, exchange_type: :topic, routing_key: events)
      end

      # Public: Subscribe to intra-service event through exchange for
      # service-specific background jobs.
      #
      # Returns nothing.
      def subscribe_to_intra_service_event
        exchange_naming = Hightops::Naming::CommonExchange.new
<commit_msg>Add class-level attributes for event-related data<commit_after>module Hightops
  # Public: Mixin module for worker classes.
  #
  # Example:
  #
  #   class SomeWorker
  #     include Hightops::Worker
  #
  #     subscribe_to_inter_service_event :upload, events: [:created]
  #   end
  #
  # Workers can be used in two different ways, namely inter-service event
  # processing and intra-service background job processing. Names of AMQP
  # components used for events are determined by project configuration.
  module Worker
    # Public: Error indicating missing implementation of #perform method
    class NotImplemented < StandardError; end

    def self.included(base)
      base.send(:include, Sneakers::Worker)
      base.send(:include, InstanceMethods)
      base.extend ClassMethods
    end

    module InstanceMethods
      # Internal: Parse JSON payload as preprocessing to perform desired
      # task for the worker and send acknowledgement.
      #
      # payload - The String of JSON payload.
      #
      # Returns nothing.
      def work(payload)
        perform HashWithIndifferentAccess.new(MultiJson.load(payload))

        ack!
      end

      # Public: After being overriden, performs desired task for the worker.
      #
      # arguments - The Hash containing arguments in concern.
      #
      # Returns nothing.
      def perform(arguments = {})
        raise Hightops::Worker::NotImplemented.new
      end
    end

    module ClassMethods
      # Public: Naming object for exchange in concern.
      attr_reader :exchange_naming
      # Public: List of events to which the worker queue listens.
      attr_reader :events

      # Public: Subscribe to inter-service event through shared exchange.
      # Name of the queue is automatically determined by name of the worker
      # class.
      #
      # tag    - The Symbol tag name of exchange to be subscribed.
      # events - The Array of event types to subscribe to.
      #
      # Returns nothing.
      def subscribe_to_inter_service_event(tag, options = {})
        @exchange_naming = Hightops::Naming::SharedExchange.new(tag: tag)
        @events = options[:events] || ['#']

        from_queue naming.to_s, options.merge(exchange: @exchange_naming.to_s, exchange_type: :topic, routing_key: @events)
      end

      # Public: Subscribe to intra-service event through exchange for
      # service-specific background jobs.
      #
      # Returns nothing.
      def subscribe_to_intra_service_event
        @exchange_naming = Hightops::Naming::CommonExchange.new

{'fraction_non_alphanumeric': 0.07031570315703158, 'fraction_numerical': 0.0, 'mean_word_length': 2.7301223241590216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7282836', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1276, 'n_words': 436}