Class: Legion::MCP::Tools::UpdateSchedule

Inherits:
MCP::Tool
  • Object
show all
Extended by:
Logging::Helper
Defined in:
lib/legion/mcp/tools/update_schedule.rb

Class Method Summary collapse

Class Method Details

.call(id:, **attrs) ⇒ Object

rubocop:disable Metrics/AbcSize



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legion/mcp/tools/update_schedule.rb', line 25

def call(id:, **attrs) # rubocop:disable Metrics/AbcSize
  log.info('Starting legion.mcp.tools.update_schedule.call')
  return error_response('legion-data is not connected') unless data_connected?
  return error_response('lex-scheduler is not loaded') unless scheduler_loaded?

  record = Legion::Extensions::Scheduler::Data::Model::Schedule[id.to_i]
  return error_response("Schedule #{id} not found") unless record

  updates = {}
  updates[:cron] = attrs[:cron] if attrs.key?(:cron)
  updates[:interval] = attrs[:interval].to_i if attrs.key?(:interval)
  updates[:active] = attrs[:active] if attrs.key?(:active)
  updates[:function_id] = attrs[:function_id].to_i if attrs.key?(:function_id)
  updates[:payload] = Legion::JSON.dump(attrs[:payload]) if attrs.key?(:payload)

  record.update(updates) unless updates.empty?
  record.refresh
  text_response(record.values)
rescue StandardError => e
  handle_exception(e, level: :warn, operation: 'legion.mcp.tools.update_schedule.call')
  log.warn("UpdateSchedule#call failed: #{e.message}")
  error_response("Failed to update schedule: #{e.message}")
end