Class: A2A::Types::TaskStatus
- Defined in:
- lib/a2a/types/task.rb
Overview
Represents the status of a task
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check if the task is still active.
-
#failure? ⇒ Boolean
Check if the status indicates failure.
-
#initialize(state:, message: nil, progress: nil, result: nil, error: nil, updated_at: nil) ⇒ TaskStatus
constructor
Initialize a new task status.
-
#success? ⇒ Boolean
Check if the status indicates success.
- #validate! ⇒ Object private
Methods inherited from BaseModel
#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(state:, message: nil, progress: nil, result: nil, error: nil, updated_at: nil) ⇒ TaskStatus
Initialize a new task status
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/a2a/types/task.rb', line 104 def initialize(state:, message: nil, progress: nil, result: nil, error: nil, updated_at: nil) @state = state = @progress = progress @result = result @error = error @updated_at = updated_at || Time.now.utc.iso8601 validate! end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
93 94 95 |
# File 'lib/a2a/types/task.rb', line 93 def error @error end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
93 94 95 |
# File 'lib/a2a/types/task.rb', line 93 def end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
93 94 95 |
# File 'lib/a2a/types/task.rb', line 93 def progress @progress end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
93 94 95 |
# File 'lib/a2a/types/task.rb', line 93 def result @result end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
93 94 95 |
# File 'lib/a2a/types/task.rb', line 93 def state @state end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
93 94 95 |
# File 'lib/a2a/types/task.rb', line 93 def updated_at @updated_at end |
Instance Method Details
#active? ⇒ Boolean
Check if the task is still active
135 136 137 |
# File 'lib/a2a/types/task.rb', line 135 def active? %w[submitted working input-required].include?(@state) end |
#failure? ⇒ Boolean
Check if the status indicates failure
127 128 129 |
# File 'lib/a2a/types/task.rb', line 127 def failure? @state == TASK_STATE_FAILED || !@error.nil? end |
#success? ⇒ Boolean
Check if the status indicates success
119 120 121 |
# File 'lib/a2a/types/task.rb', line 119 def success? @state == TASK_STATE_COMPLETED && @error.nil? end |
#validate! ⇒ Object (private)
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/a2a/types/task.rb', line 141 def validate! validate_required(:state, :updated_at) validate_inclusion(:state, VALID_TASK_STATES) return unless @progress validate_type(:progress, Numeric) return if @progress.between?(0.0, 1.0) raise ArgumentError, "progress must be between 0.0 and 1.0" end |