Class: Kie::GeneralTask
- Inherits:
-
Object
- Object
- Kie::GeneralTask
- Includes:
- Task
- Defined in:
- lib/kie/general_task.rb
Overview
Represents an asynchronous task for General API endpoints
Constant Summary collapse
- RECORD_INFO_ENDPOINT =
"/api/v1/jobs/recordInfo"- STATUS_MAP =
Status mapping from General API raw states to normalized statuses
{ waiting: :processing, generating: :processing, success: :success, fail: :failed }.freeze
Constants included from Task
Instance Attribute Summary collapse
-
#cost_time ⇒ Object
readonly
Returns the value of attribute cost_time.
-
#fail_code ⇒ Object
readonly
Returns the value of attribute fail_code.
-
#fail_message ⇒ Object
readonly
Returns the value of attribute fail_message.
-
#raw_status ⇒ Object
readonly
Returns the value of attribute raw_status.
-
#task_id ⇒ Object
(also: #id)
readonly
Returns the value of attribute task_id.
Instance Method Summary collapse
-
#error_message ⇒ Object
Returns the error message from the failed task, or nil if not failed.
-
#initialize(client:, task_id:) ⇒ GeneralTask
constructor
A new instance of GeneralTask.
-
#pending? ⇒ Boolean
Returns true when task is in pending/waiting state (not yet processing).
-
#raise_task_error! ⇒ Object
Raises the appropriate exception based on the failure reason.
- #refresh! ⇒ Object
-
#status ⇒ Object
Returns normalized status (:processing, :success, :failed).
-
#urls ⇒ Object
(also: #result_urls)
Returns array of result URLs.
Methods included from Task
#completed?, #failed?, #processing?, #success?, #wait
Constructor Details
#initialize(client:, task_id:) ⇒ GeneralTask
Returns a new instance of GeneralTask.
24 25 26 27 28 29 30 31 32 |
# File 'lib/kie/general_task.rb', line 24 def initialize(client:, task_id:) @client = client @task_id = task_id @raw_status = nil @result_urls = [] @cost_time = nil @fail_code = nil @fail_message = nil end |
Instance Attribute Details
#cost_time ⇒ Object (readonly)
Returns the value of attribute cost_time.
20 21 22 |
# File 'lib/kie/general_task.rb', line 20 def cost_time @cost_time end |
#fail_code ⇒ Object (readonly)
Returns the value of attribute fail_code.
20 21 22 |
# File 'lib/kie/general_task.rb', line 20 def fail_code @fail_code end |
#fail_message ⇒ Object (readonly)
Returns the value of attribute fail_message.
20 21 22 |
# File 'lib/kie/general_task.rb', line 20 def @fail_message end |
#raw_status ⇒ Object (readonly)
Returns the value of attribute raw_status.
20 21 22 |
# File 'lib/kie/general_task.rb', line 20 def raw_status @raw_status end |
#task_id ⇒ Object (readonly) Also known as: id
Returns the value of attribute task_id.
20 21 22 |
# File 'lib/kie/general_task.rb', line 20 def task_id @task_id end |
Instance Method Details
#error_message ⇒ Object
Returns the error message from the failed task, or nil if not failed
56 57 58 |
# File 'lib/kie/general_task.rb', line 56 def @fail_message end |
#pending? ⇒ Boolean
Returns true when task is in pending/waiting state (not yet processing)
61 62 63 |
# File 'lib/kie/general_task.rb', line 61 def pending? @raw_status.nil? || @raw_status == :waiting end |
#raise_task_error! ⇒ Object
Raises the appropriate exception based on the failure reason
66 67 68 69 |
# File 'lib/kie/general_task.rb', line 66 def raise_task_error! error_class = @fail_code == "CONTENT_POLICY" ? ContentPolicyError : TaskFailedError raise error_class.new(@fail_message, fail_code: @fail_code) end |
#refresh! ⇒ Object
34 35 36 37 38 |
# File 'lib/kie/general_task.rb', line 34 def refresh! response = @client.connection.get(RECORD_INFO_ENDPOINT, taskId: @task_id) handle_response(response) self end |
#status ⇒ Object
Returns normalized status (:processing, :success, :failed)
41 42 43 44 45 |
# File 'lib/kie/general_task.rb', line 41 def status return :processing if @raw_status.nil? STATUS_MAP.fetch(@raw_status, :processing) end |
#urls ⇒ Object Also known as: result_urls
Returns array of result URLs
48 49 50 |
# File 'lib/kie/general_task.rb', line 48 def urls @result_urls end |