Class: AsposeWordsCloud::JobHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/aspose_words_cloud/job_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, request, info) ⇒ JobHandler

Returns a new instance of JobHandler.



30
31
32
33
34
35
# File 'lib/aspose_words_cloud/job_handler.rb', line 30

def initialize(api, request, info)
  @api = api
  @request = request
  @info = info
  @result = nil
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



28
29
30
# File 'lib/aspose_words_cloud/job_handler.rb', line 28

def result
  @result
end

Instance Method Details

#messageObject



41
42
43
# File 'lib/aspose_words_cloud/job_handler.rb', line 41

def message
  @info.message || ''
end

#statusObject



37
38
39
# File 'lib/aspose_words_cloud/job_handler.rb', line 37

def status
  @info.status || ''
end

#updateObject

Raises:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aspose_words_cloud/job_handler.rb', line 45

def update
  raise ApiError.new(code: 400, message: 'Invalid job id.', response_headers: {}, response_body: '') if @info.job_id.nil?

  parts = @api.call_job_result(@info.job_id)
  if parts.length >= 1
    @info = @api.api_client.deserialize_job_info_part(parts[0])
    if parts.length >= 2 && succeeded?
      @result = @api.api_client.deserialize_http_response_part(@request, parts[1][:data])
    end
  end

  @result
end

#wait_result(update_interval = 3) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aspose_words_cloud/job_handler.rb', line 59

def wait_result(update_interval = 3)
  while queued? || processing?
    sleep(update_interval)
    update
  end

  update if succeeded? && @result.nil?

  unless succeeded?
    raise ApiError.new(
      code: 400,
      message: "Job failed with status \"#{status}\" - \"#{message}\".",
      response_headers: {},
      response_body: ''
    )
  end

  @result
end