Class: Readiness::Zendesk::JobStatuses
- Defined in:
- lib/support_readiness/zendesk/job_statuses.rb
Overview
Defines the class JobStatuses within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #id ⇒ Object
- #job_type ⇒ Object
- #message ⇒ Object
- #progress ⇒ Object
- #results ⇒ Object
- #status ⇒ Object
- #total ⇒ Object
Class Method Summary collapse
-
.find(client, jid) ⇒ Hash
Locates a job status within Zendesk.
-
.find!(client, jid) ⇒ Hash
Locates a job status within Zendesk.
-
.find_many(client, jids) ⇒ Array
Locates up to 100 job statuses within Zendesk.
-
.list(client) ⇒ Array
Lists the first 100 job statuses.
-
.wait_for_completetion(client, job, interval = 5, verbose = true) ⇒ Object
Waits for a job to complete.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ JobStatuses
constructor
Creates a new JobStatuses instance.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ JobStatuses
Creates a new Readiness::Zendesk::JobStatuses instance
24 25 26 27 28 29 30 31 32 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 24 def initialize(object = {}) @id = object['id'] @job_type = object['job_type'] @message = object['message'] @progress = object['progress'] @results = object['results'] @status = object['status'] @total = object['total'] end |
Instance Attribute Details
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def id @id end |
#job_type ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def job_type @job_type end |
#message ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def @message end |
#progress ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def progress @progress end |
#results ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def results @results end |
#status ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def status @status end |
#total ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 13 def total @total end |
Class Method Details
.find(client, jid) ⇒ Hash
Locates a job status within Zendesk. This will not exit on error (except Authentication errors)
77 78 79 80 81 82 83 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 77 def self.find(client, jid) response = client.connection.get("job_statuses/#{jid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: jid }) unless response.status == 200 return JobStatuses.new(Oj.load(response.body)['job_status']) if response.status == 200 Oj.load(response.body) end |
.find!(client, jid) ⇒ Hash
Locates a job status within Zendesk. This will exit on error
104 105 106 107 108 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 104 def self.find!(client, jid) response = client.connection.get("job_statuses/#{jid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find job status', id: jid }) unless response.status == 200 JobStatuses.new(Oj.load(response.body)['job_status']) end |
.find_many(client, jids) ⇒ Array
Locates up to 100 job statuses within Zendesk.
129 130 131 132 133 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 129 def self.find_many(client, jids) response = client.connection.get("job_statuses/show_many?ids=#{jids.join(',')}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: jids }) unless response.status == 200 Oj.load(response.body)['job_statuses'].map { |o| JobStatuses.new(o) } end |
.list(client) ⇒ Array
Lists the first 100 job statuses
52 53 54 55 56 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 52 def self.list(client) response = client.connection.get("job_statuses?page[size]=100") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 Oj.load(response.body)['job_statuses'].map { |j| JobStatuses.new(j) } end |
.wait_for_completetion(client, job, interval = 5, verbose = true) ⇒ Object
Waits for a job to complete. Be mindful of API limits when setting the wait interval
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/support_readiness/zendesk/job_statuses.rb', line 174 def self.wait_for_completetion(client, job, interval = 5, verbose = true) loop do puts "Waiting #{interval} seconds before checking #{job.id}" if verbose sleep interval print "Rechecking status of #{job.id}..." if verbose job = JobStatuses.find!(client, job.id) puts "status is #{job.status}" if verbose break if %w[failed completed].include? job.status end puts "Job is finished with status of #{job.status}" if verbose job end |