Sha256: 3e65c7b82836ac3fad5ac41b090e2d1364a65df0ebd327bb5d39fb26e910d7ee

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

module ProxyAPI
  module ForemanDynflow
    class DynflowProxy
      PREFIX = 'dynflow'.freeze

      class Task < ProxyAPI::Resource
        def initialize(args)
          @url = "#{args[:url]}/#{PREFIX}/tasks"
          super args
          @connect_params[:headers] ||= {}
          @connect_params[:headers]['content-type'] = 'application/json'
        end
      end

      def initialize(args)
        @args = args
      end

      # Initiate the command
      def trigger_task(action_name, action_input)
        payload = MultiJson.dump(:action_name => action_name, :action_input => action_input)
        MultiJson.load(Task.new(@args).send(:post, payload))
      end

      # Cancel the command
      def cancel_task(proxy_task_id)
        MultiJson.load(Task.new(@args).send(:post, '', "#{proxy_task_id}/cancel"))
      end

      def status_of_task(proxy_task_id)
        MultiJson.load(Task.new(@args).send(:get, "#{proxy_task_id}/status"))
      end

      def tasks_count(state)
        MultiJson.load(Task.new(@args).send(:get, "count?state=#{state}"))['count'].to_i
      end

      def task_states(ids)
        payload = MultiJson.dump(:task_ids => ids)
        MultiJson.load(Task.new(@args).send(:post, payload, 'status'))
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman-tasks-0.14.6 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.15.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.14.5 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.14.4 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.14.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.14.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.14.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.14.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.13.4 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.13.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.13.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.13.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb