<commit_before>require 'celluloid/autostart'
require 'yaml'

module RabbitWQ
  class MessageHandler

    include Celluloid
    include Logging
    include Queues

    REQUEUE = true

    def call( options )
      Time.zone = RabbitWQ.configuration.time_zone

      channel       = options[:channel]
      delivery_info = options[:delivery_info]
      metadata      = options[:metadata]
      #headers       = metadata[:headers]
      payload       = options[:payload]

      debug "PAYLOAD ARRIVED #{payload}"

      worker = YAML::load( payload )
      worker.call
      channel.ack delivery_info.delivery_tag
    rescue => e
      handle_error( worker, e, channel, delivery_info, payload, metadata )
    end

  protected

    def handle_error( worker, e, channel, delivery_info, payload, metadata )
      headers = metadata[:headers]

      error_metadata = { type: e.class.name,
                         message: e.message,<commit_msg>Add logging of worker instance details to message handler.<commit_after>require 'celluloid/autostart'
require 'yaml'

module RabbitWQ
  class MessageHandler

    include Celluloid
    include Logging
    include Queues

    REQUEUE = true

    def call( options )
      Time.zone = RabbitWQ.configuration.time_zone

      channel       = options[:channel]
      delivery_info = options[:delivery_info]
      metadata      = options[:metadata]
      #headers       = metadata[:headers]
      payload       = options[:payload]

      debug "PAYLOAD ARRIVED #{payload}"

      worker = YAML::load( payload )
      info ANSI.yellow { "WORKER [#{worker.object_id}] " + worker.inspect }
      worker.call
      channel.ack delivery_info.delivery_tag
    rescue => e
      handle_error( worker, e, channel, delivery_info, payload, metadata )
    end

  protected

    def handle_error( worker, e, channel, delivery_info, payload, metadata )
      headers = metadata[:headers]

      error_metadata = { type: e.class.name,
                         message: e.message,
{'fraction_non_alphanumeric': 0.08512769153730596, 'fraction_numerical': 0.0, 'mean_word_length': 2.593525179856115, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1534530', 'n_tokens_mistral': 572, 'n_tokens_neox': 548, 'n_words': 146}