Class: ActionMCP::ToolExecutionJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- ActionMCP::ToolExecutionJob
- Includes:
- ActiveJob::Continuable
- Defined in:
- app/jobs/action_mcp/tool_execution_job.rb
Overview
ActiveJob for executing tools asynchronously in task-augmented mode Part of MCP 2025-11-25 Tasks specification with ActiveJob::Continuable support
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.handle_job_discard(job, error) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/jobs/action_mcp/tool_execution_job.rb', line 150 def self.handle_job_discard(job, error) task_id = job.arguments.first task = Session::Task.find_by(id: task_id) return unless task&.persisted? Rails.logger.error "[ToolExecutionJob] Discarding job for task #{task_id}: #{error.class} - #{error.}" Rails.logger.error error.backtrace&.first(10)&.join("\n") task.with_lock do return if task.terminal? task.update!( status_message: "Job failed: #{error.}", result_payload: { code: -32_603, message: "Job failed: #{error.}" }, continuation_state: { step: :failed, error: { class: error.class.name, message: error. }, timestamp: Time.current.iso8601 } ) task.mark_failed! end end |
Instance Method Details
#perform(task_id, tool_name, arguments, meta = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/jobs/action_mcp/tool_execution_job.rb', line 23 def perform(task_id, tool_name, arguments, = {}) @task = step(:load_task, task_id) return if @task.nil? || @task.terminal? @session = step(:validate_session, @task) return unless @session @tool = step(:prepare_tool, @session, tool_name, arguments, @task) return unless @tool step(:execute_tool) do result = execute_with_reloader(@tool, @session) update_task_result(@task, result) end end |