Class: Heracles::Wrapper::Request::CreateJob

Inherits:
Object
  • Object
show all
Defined in:
lib/heracles-wrapper/request/create_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}) ⇒ CreateJob

Returns a new instance of CreateJob.



23
24
25
26
27
28
29
# File 'lib/heracles-wrapper/request/create_job.rb', line 23

def initialize(config, options = {})
  @config = config
  @workflow_name = options.fetch(:workflow_name)
  @parent_job_id = options.fetch(:parent_job_id, nil)
  @parameters = options.fetch(:parameters, {})
  @url = URI.parse(File.join(config.heracles_base_url, 'jobs'))
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/heracles-wrapper/request/create_job.rb', line 16

def config
  @config
end

#parametersObject (readonly)

Returns the value of attribute parameters.



16
17
18
# File 'lib/heracles-wrapper/request/create_job.rb', line 16

def parameters
  @parameters
end

#parent_job_idObject (readonly)

Returns the value of attribute parent_job_id.



16
17
18
# File 'lib/heracles-wrapper/request/create_job.rb', line 16

def parent_job_id
  @parent_job_id
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/heracles-wrapper/request/create_job.rb', line 16

def url
  @url
end

#workflow_nameObject (readonly)

Returns the value of attribute workflow_name.



16
17
18
# File 'lib/heracles-wrapper/request/create_job.rb', line 16

def workflow_name
  @workflow_name
end

Instance Method Details

#as_jsonObject



31
32
33
34
35
36
37
38
39
# File 'lib/heracles-wrapper/request/create_job.rb', line 31

def as_json
  {
    :api_key => config.api_key,
    :workflow_name => workflow_name,
    :parameters => parameters
  }.tap {|hash|
    hash[:parent_job_id] = parent_job_id if parent_job_id
  }
end

#callObject

Need to accept a self-signed cert. Hits a given URL Syncrhonously waits for response.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/heracles-wrapper/request/create_job.rb', line 44

def call
  decorate_response(
    RestClient.post(
      url.to_s,
      as_json,
      {
        :content_type => :json,
        :accept => :json,
        :verify_ssl => OpenSSL::SSL::VERIFY_NONE
      }
    )
  )
rescue RestClient::Exception => e
  raise Heracles::Wrapper::RequestFailure.new(e.response)
end