Module: Idcf::Ilb::ClientExtensions::Job

Included in:
Idcf::Ilb::Client
Defined in:
lib/idcf/ilb/client_extensions/job.rb

Overview

SDK APIs for job resource

Instance Method Summary collapse

Instance Method Details

#check_job(id, headers = {}, callback_and_args = [], specify_res_id = true) ⇒ Response

Check job result Get a resource data

Parameters:

  • id (String)

    ID of target job

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/idcf/ilb/client_extensions/job.rb', line 32

def check_job(id, headers = {}, callback_and_args = [], specify_res_id = true)
  flag = false
  1.upto(20) do |n|
    @res = get_job(id, headers)
    if @res.body["job_status"] == "Success"
      flag = true
      break
    elsif @res.body["job_status"] == "Failed"
      raise(
        ApiError,
        "API Failed."
      )
    else
      sleep 2 * n
    end
  end

  return if "DELETE" == @res.body["method"]
  if flag == true
    if specify_res_id == true
      res_id = @res.body["resource_id"]
      callback_and_args << res_id
    end
    callback_and_args.empty? ? true : __send__(*callback_and_args, headers)
  else
    raise(
      ApiError,
      "JOB Timeout."
    )
  end
end

#get_job(id, headers = {}) ⇒ Response

Get a job

Parameters:

  • id (String)

    ID of target job

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



23
24
25
# File 'lib/idcf/ilb/client_extensions/job.rb', line 23

def get_job(id, headers = {})
  get!("jobs/#{id}", {}, headers)
end

#jobs(headers = {}) ⇒ Array<Resources::Job>

Get an array of existing job objects.

Parameters:

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



68
69
70
71
72
# File 'lib/idcf/ilb/client_extensions/job.rb', line 68

def jobs(headers = {})
  list_jobs(headers).resources.map do |job|
    Resources::Job.new(self, job)
  end
end

#list_jobs(attributes = {}, headers = {}) ⇒ Response

Get list of existing jobs

Parameters:

  • attributes (Hash) (defaults to: {})

    request attributes

  • headers (Hash) (defaults to: {})

    HTTP request headers

Options Hash (attributes):

  • :resource (String)

    name of resource (optional)

  • :method (String)

    name of http method (optional)

Returns:



13
14
15
16
# File 'lib/idcf/ilb/client_extensions/job.rb', line 13

def list_jobs(attributes = {}, headers = {})
  Validators::Job.validate_attributes!(attributes, :list)
  get!("jobs", attributes, headers)
end