Module: Cyclid::Client::Job

Included in:
Tilapia
Defined in:
lib/cyclid/client/job.rb

Overview

Job related methods

Instance Method Summary collapse

Instance Method Details

#job_get(organization, jobid) ⇒ Hash

Get details of a job

Parameters:

  • organization (String)

    Organization name.

  • jobid (Integer)

    Job ID to retrieve. The ID must be a valid job for the organization.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



53
54
55
56
57
58
59
# File 'lib/cyclid/client/job.rb', line 53

def job_get(organization, jobid)
  uri = server_uri("/organizations/#{organization}/jobs/#{jobid}")
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#job_list(organization, args = {}) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/cyclid/client/job.rb', line 97

def job_list(organization, args = {})
  # Convert the args hash into a query string
  query = args.map { |k, v| "#{k}=#{v}" }.join('&')

  uri = server_uri("/organizations/#{organization}/jobs", query)
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#job_log(organization, jobid) ⇒ Hash

Get a job log

Parameters:

  • organization (String)

    Organization name.

  • jobid (Integer)

    Job ID to retrieve. The ID must be a valid job for the organization.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



81
82
83
84
85
86
87
# File 'lib/cyclid/client/job.rb', line 81

def job_log(organization, jobid)
  uri = server_uri("/organizations/#{organization}/jobs/#{jobid}/log")
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#job_stats(organization) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/cyclid/client/job.rb', line 89

def job_stats(organization)
  uri = server_uri("/organizations/#{organization}/jobs", 'stats_only=true')
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#job_status(organization, jobid) ⇒ Hash

Get a job status

Parameters:

  • organization (String)

    Organization name.

  • jobid (Integer)

    Job ID to retrieve. The ID must be a valid job for the organization.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



67
68
69
70
71
72
73
# File 'lib/cyclid/client/job.rb', line 67

def job_status(organization, jobid)
  uri = server_uri("/organizations/#{organization}/jobs/#{jobid}/status")
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#job_submit(organization, job, type) ⇒ Hash

Submit a job

Examples:

Submit a job in JSON format

job = File.read('job.json')
job_submit('example', job, 'json')

Submit a job in YAML format

job = File.read('job.yml')
job_submit('example', job, 'yaml')

Parameters:

  • organization (String)

    Organization name.

  • job (String)

    Raw job data in either JSON or YAML

  • type (String)

    Job data format; either ‘json’ or ‘yaml’

Returns:

  • (Hash)

    Decoded server response object.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cyclid/client/job.rb', line 32

def job_submit(organization, job, type)
  uri = server_uri("/organizations/#{organization}/jobs")
  case type
  when 'yaml'
    res_data = api_raw_post(uri, job, 'application/x-yaml')
  when 'json'
    res_data = api_raw_post(uri, job, 'application/json')
  else
    raise "Unknown job format #{type}"
  end
  @logger.debug res_data

  return res_data
end