Class: Readiness::Zendesk::AppJobStatuses

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/zendesk/app_job_statuses.rb

Overview

Defines the class AppJobStatuses within the module Readiness::Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.12

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = {}) ⇒ AppJobStatuses

Creates a new Readiness::Zendesk::AppJobStatuses instance

Examples:

require 'support_readiness'
Readiness::Zendesk::AppJobStatuses.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.12



24
25
26
27
28
29
30
31
32
33
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 24

def initialize(object = {})
  @app_id = object['app_id']
  @app_url = object['app_url']
  @id = object['id']
  @message = object['message']
  @progress = object['progress']
  @retry_in = object['retry_in']
  @status = object['status']
  @total = object['total']
end

Instance Attribute Details

#app_idObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def app_id
  @app_id
end

#app_urlObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def app_url
  @app_url
end

#idObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def id
  @id
end

#messageObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def message
  @message
end

#progressObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def progress
  @progress
end

#retry_inObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def retry_in
  @retry_in
end

#statusObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def status
  @status
end

#totalObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 13

def total
  @total
end

Class Method Details

.find(client, jid) ⇒ Hash

Locates an app job status within Zendesk. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::AppJobStatuses.find(client, '8b726e606741012ffc2d782bcb7848fe')
pp job.status
# => "completed"

Parameters:

  • client (Object)

    An instance of Client

  • jid (String)

    The job status ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



54
55
56
57
58
59
60
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 54

def self.find(client, jid)
  response = client.connection.get("apps/job_statuses/#{jid}")
  handle_request_error(0, 'Zendesk', response.status,  { action: 'get', id: jid }) unless response.status == 200
  return AppJobStatuses.new(Oj.load(response.body)) if response.status == 200

  Oj.load(response.body)
end

.find!(client, jid) ⇒ Object

Locates an app job status within Zendesk. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::AppJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
pp job.status
# => "completed"

Parameters:

  • client (Object)

    An instance of Client

  • jid (String)

    The job status ID to find

Returns:

  • (Object)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



81
82
83
84
85
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 81

def self.find!(client, jid)
  response = client.connection.get("apps/job_statuses/#{jid}")
  handle_request_error(1, 'Zendesk', response.status, { action: 'Find app job status', id: jid }) unless response.status == 200
  AppJobStatuses.new(Oj.load(response.body))
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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::AppJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
completed_job = Readiness::Zendesk::AppJobStatuses.wait_for_completetion(client, job, 10, true)
# => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
# => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is queued
# => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
# => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is working
# => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
# => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is completed
# => Job is finished with status of completed
pp completed_job.status
# => "completed"
require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::AppJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
completed_job = Readiness::Zendesk::AppJobStatuses.wait_for_completetion(client, job, 5, false)
pp completed_job.status
# => "completed"

Parameters:

  • client (Object)

    An instance of Client

  • job (Object)
  • interval (Integer) (defaults to: 5)

    The time (in seconds) between checks

  • verbose (Boolean) (defaults to: true)

    Whether or not to output messages

Returns:

Author:

  • Jason Colyer

Since:

  • 1.0.12



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/support_readiness/zendesk/app_job_statuses.rb', line 126

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 = AppJobStatuses.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