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



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
# 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

  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



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.



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

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

Options Hash (attributes):

  • :resource (String)

    name of resource (optional)

  • :method (String)

    name of http method (optional)



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