<commit_before>module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::ConfigurationScript
  extend ActiveSupport::Concern

  module ClassMethods

    def create_in_provider(manager_id, params)
      manager = ExtManagementSystem.find(manager_id)
      job_template = manager.with_provider_connection do |connection|
        connection.api.job_templates.create!(params)
      end

      # Get the record in our database
      # TODO: This needs to be targeted refresh so it doesn't take too long
      EmsRefresh.queue_refresh(manager, nil, true)

      find_by!(:manager_id => manager.id, :manager_ref => job_template.id)
    end

    def create_in_provider_queue(manager_id, params, auth_user = nil)
      manager = ExtManagementSystem.find(manager_id)
      task_opts = {
        :action => "Creating Ansible Tower Job Template",
        :userid => auth_user || "system"
      }
      queue_opts = {
        :args        => [manager_id, params],
        :class_name  => self.name,
        :method_name => "create_in_provider",
        :priority    => MiqQueue::HIGH_PRIORITY,
        :role        => "ems_operations",
        :zone        => manager.my_zone
      }

      MiqTask.generic_action_with_callback(task_opts, queue_opts)<commit_msg>Move AnsibleTower to use MiqTask.wait_for_taskid<commit_after>module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::ConfigurationScript
  extend ActiveSupport::Concern

  module ClassMethods

    def create_in_provider(manager_id, params)
      manager = ExtManagementSystem.find(manager_id)
      job_template = manager.with_provider_connection do |connection|
        connection.api.job_templates.create!(params)
      end

      # Get the record in our database
      # TODO: This needs to be targeted refresh so it doesn't take too long
      task_ids = EmsRefresh.queue_refresh(manager)
      task_ids.each { |tid| MiqTask.wait_for_taskid(tid) }

      find_by!(:manager_id => manager.id, :manager_ref => job_template.id)
    end

    def create_in_provider_queue(manager_id, params, auth_user = nil)
      manager = ExtManagementSystem.find(manager_id)
      task_opts = {
        :action => "Creating Ansible Tower Job Template",
        :userid => auth_user || "system"
      }
      queue_opts = {
        :args        => [manager_id, params],
        :class_name  => self.name,
        :method_name => "create_in_provider",
        :priority    => MiqQueue::HIGH_PRIORITY,
        :role        => "ems_operations",
        :zone        => manager.my_zone
      }

      MiqTask.generic_action_with_callback(task_opts, queue_opts)
{'fraction_non_alphanumeric': 0.09410864575363427, 'fraction_numerical': 0.0, 'mean_word_length': 3.1181102362204722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6444939', 'n_tokens_mistral': 785, 'n_tokens_neox': 760, 'n_words': 159}