Class: LanguageOperator::Agent::ExecutionState
- Inherits:
-
Object
- Object
- LanguageOperator::Agent::ExecutionState
- Defined in:
- lib/language_operator/agent/execution_state.rb
Overview
Execution State Manager
Manages the execution state of agents to prevent concurrent executions. Thread-safe implementation ensures only one execution runs at a time.
Instance Attribute Summary collapse
-
#current_execution_id ⇒ Object
readonly
Returns the value of attribute current_execution_id.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#complete_execution(result = nil) ⇒ Object
Mark execution as completed.
-
#current_info ⇒ Hash
Get current execution information.
-
#fail_execution(error) ⇒ void
Mark execution as failed.
-
#initialize ⇒ ExecutionState
constructor
Initialize a new execution state.
-
#running? ⇒ Boolean
Check if an execution is currently running.
-
#start_execution(execution_id) ⇒ void
Start a new execution.
Constructor Details
#initialize ⇒ ExecutionState
Initialize a new execution state
21 22 23 24 25 26 |
# File 'lib/language_operator/agent/execution_state.rb', line 21 def initialize @mutex = Mutex.new @current_execution_id = nil @started_at = nil @status = :idle # :idle, :running, :completed, :failed end |
Instance Attribute Details
#current_execution_id ⇒ Object (readonly)
Returns the value of attribute current_execution_id.
18 19 20 |
# File 'lib/language_operator/agent/execution_state.rb', line 18 def current_execution_id @current_execution_id end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
18 19 20 |
# File 'lib/language_operator/agent/execution_state.rb', line 18 def started_at @started_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
18 19 20 |
# File 'lib/language_operator/agent/execution_state.rb', line 18 def status @status end |
Instance Method Details
#complete_execution(result = nil) ⇒ Object
Mark execution as completed
50 51 52 53 54 55 |
# File 'lib/language_operator/agent/execution_state.rb', line 50 def complete_execution(result = nil) @mutex.synchronize do @status = :completed result end end |
#current_info ⇒ Hash
Get current execution information
78 79 80 81 82 83 84 85 86 |
# File 'lib/language_operator/agent/execution_state.rb', line 78 def current_info @mutex.synchronize do { status: @status, execution_id: @current_execution_id, started_at: @started_at } end end |
#fail_execution(error) ⇒ void
This method returns an undefined value.
Mark execution as failed
61 62 63 64 65 66 |
# File 'lib/language_operator/agent/execution_state.rb', line 61 def fail_execution(error) @mutex.synchronize do @status = :failed @last_error = error end end |
#running? ⇒ Boolean
Check if an execution is currently running
71 72 73 |
# File 'lib/language_operator/agent/execution_state.rb', line 71 def running? @mutex.synchronize { @status == :running } end |
#start_execution(execution_id) ⇒ void
This method returns an undefined value.
Start a new execution
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/language_operator/agent/execution_state.rb', line 33 def start_execution(execution_id) @mutex.synchronize do if @status == :running raise ExecutionInProgressError, "Execution #{@current_execution_id} already running" end @current_execution_id = execution_id @started_at = Time.now @status = :running end end |