<commit_before>module MiqRequestTask::StateMachine
  delegate :my_role, :to => :miq_request
  delegate :my_zone, :to => :source,      :allow_nil => true

  def my_task_id
    "#{self.class.base_model.name.underscore}_#{id}"
  end

  def signal_abort
    signal(:abort)
  end

  def signal(phase)
    return signal(:finish) if ![:finish, :provision_error].include?(phase.to_sym) && prematurely_finished?

    self.phase = phase.to_s
    $log.info("Starting Phase <#{self.phase}>")
    save

    begin
      send(phase)
    rescue => err
      if [:finish, :provision_error].include?(phase.to_sym)
        _log.error("[#{err.message}] encountered during [#{phase}]")
        _log.log_backtrace(err)
      else
        phase_context.delete(:error_message)

        # HACK: Psych is unable to deserialize an Exception that contains a
        #   NameError::message as its message.  When deserialized, it will raise
        #   "TypeError: allocator undefined for NameError::message".  Calling
        #   .message will dereference it and turn it into a String which is
        #   serializable.  For more information about NameError::message, see
        #   http://www.carboni.ca/blog/p/Ruby-Did-You-Know-That-5-NameErrormessage
        #
        #   In addition, backtrace information is not available, because it is<commit_msg>Adding request id to my_task_id string.<commit_after>module MiqRequestTask::StateMachine
  delegate :my_role, :to => :miq_request
  delegate :my_zone, :to => :source,      :allow_nil => true

  def my_task_id
    "#{miq_request_id}_#{self.class.base_model.name.underscore}_#{id}"
  end

  def signal_abort
    signal(:abort)
  end

  def signal(phase)
    return signal(:finish) if ![:finish, :provision_error].include?(phase.to_sym) && prematurely_finished?

    self.phase = phase.to_s
    $log.info("Starting Phase <#{self.phase}>")
    save

    begin
      send(phase)
    rescue => err
      if [:finish, :provision_error].include?(phase.to_sym)
        _log.error("[#{err.message}] encountered during [#{phase}]")
        _log.log_backtrace(err)
      else
        phase_context.delete(:error_message)

        # HACK: Psych is unable to deserialize an Exception that contains a
        #   NameError::message as its message.  When deserialized, it will raise
        #   "TypeError: allocator undefined for NameError::message".  Calling
        #   .message will dereference it and turn it into a String which is
        #   serializable.  For more information about NameError::message, see
        #   http://www.carboni.ca/blog/p/Ruby-Did-You-Know-That-5-NameErrormessage
        #
        #   In addition, backtrace information is not available, because it is
{'fraction_non_alphanumeric': 0.11053412462908012, 'fraction_numerical': 0.000741839762611276, 'mean_word_length': 3.067873303167421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '242826', 'n_tokens_mistral': 837, 'n_tokens_neox': 830, 'n_words': 212}