<commit_before># frozen_string_literal: true

module Appsignal
  class Hooks
    # @api private
    class ActiveJobHook < Appsignal::Hooks::Hook
      register :active_job

      def dependencies_present?
        defined?(::ActiveJob)
      end

      def install
        ::ActiveJob::Base
          .extend ::Appsignal::Hooks::ActiveJobHook::ActiveJobClassInstrumentation
      end

      # @todo Add queue time support for Rails 6's enqueued_at. For both
      #   existing and new transactions.
      module ActiveJobClassInstrumentation
        def execute(job)
          current_transaction = Appsignal::Transaction.current
          transaction =
            if current_transaction.nil_transaction?
              # No standalone integration started before ActiveJob integration.
              # We don't have a separate integration for this QueueAdapter like
              # we do for Sidekiq.
              #
              # Prefer job_id from provider, instead of ActiveJob's internal ID.
              Appsignal::Transaction.create(
                job["provider_job_id"] || job["job_id"],
                Appsignal::Transaction::BACKGROUND_JOB,
                Appsignal::Transaction::GenericRequest.new({})
              )
            else
              current_transaction
            end

          super
        rescue Exception => exception # rubocop:disable Lint/RescueException<commit_msg>Removed outdated TODO comment<commit_after># frozen_string_literal: true

module Appsignal
  class Hooks
    # @api private
    class ActiveJobHook < Appsignal::Hooks::Hook
      register :active_job

      def dependencies_present?
        defined?(::ActiveJob)
      end

      def install
        ::ActiveJob::Base
          .extend ::Appsignal::Hooks::ActiveJobHook::ActiveJobClassInstrumentation
      end

      module ActiveJobClassInstrumentation
        def execute(job)
          current_transaction = Appsignal::Transaction.current
          transaction =
            if current_transaction.nil_transaction?
              # No standalone integration started before ActiveJob integration.
              # We don't have a separate integration for this QueueAdapter like
              # we do for Sidekiq.
              #
              # Prefer job_id from provider, instead of ActiveJob's internal ID.
              Appsignal::Transaction.create(
                job["provider_job_id"] || job["job_id"],
                Appsignal::Transaction::BACKGROUND_JOB,
                Appsignal::Transaction::GenericRequest.new({})
              )
            else
              current_transaction
            end

          super
        rescue Exception => exception # rubocop:disable Lint/RescueException
{'fraction_non_alphanumeric': 0.06632277081798084, 'fraction_numerical': 0.00036845983787767134, 'mean_word_length': 2.117106773823192, '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': '4419678', 'n_tokens_mistral': 656, 'n_tokens_neox': 631, 'n_words': 171}