Sha256: 852621b14a61551792e82c87fb281647303e461d88930843ae0894bdd1781ced

Contents?: true

Size: 838 Bytes

Versions: 27

Compression:

Stored size: 838 Bytes

Contents

module AnsibleTowerClient
  class JobTemplateV2 < JobTemplate
    def launch(options = {})
      launch_url = "#{url}launch/"
      options = options.dup
      new_limit = options.delete(:limit) || options.delete('limit')
      response = with_temporary_changes(new_limit) do
        api.post(launch_url, options).body
      end

      job = JSON.parse(response)
      api.jobs.find(job['job'])
    end

    private

    def with_temporary_changes(in_limit)
      old_limit = limit
      new_limit = in_limit
      patch("{ \"limit\": \"#{new_limit}\" }")
      begin
        yield
      ensure
        patch("{ \"limit\": \"#{old_limit}\" }")
      end
    end

    def patch(body)
      api.patch do |req|
        req.url(url)
        req.headers['Content-Type'] = 'application/json'
        req.body = body
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ansible_tower_client-0.21.3 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.21.2 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.21.1 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.21.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.20.2 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.20.1 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.20.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.19.1 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.19.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.18.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.17.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.16.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.15.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.14.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.13.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.12.2 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.12.1 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.12.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.11.0 lib/ansible_tower_client/v2/job_template_v2.rb
ansible_tower_client-0.10.0 lib/ansible_tower_client/v2/job_template_v2.rb