24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/legion/mcp/tools/create_schedule.rb', line 24
def call(function_id:, cron: nil, interval: nil, active: true, payload: {})
log.info('Starting legion.mcp.tools.create_schedule.call')
return error_response('legion-data is not connected') unless data_connected?
return error_response('lex-scheduler is not loaded') unless scheduler_loaded?
return error_response('cron or interval is required') if cron.nil? && interval.nil?
attrs = {
function_id: function_id.to_i,
active: active,
payload: Legion::JSON.dump(payload),
last_run: Time.at(0)
}
attrs[:cron] = cron if cron
attrs[:interval] = interval.to_i if interval
id = Legion::Extensions::Scheduler::Data::Model::Schedule.insert(attrs)
record = Legion::Extensions::Scheduler::Data::Model::Schedule[id]
text_response(record.values)
rescue StandardError => e
handle_exception(e, level: :warn, operation: 'legion.mcp.tools.create_schedule.call')
log.warn("CreateSchedule#call failed: #{e.message}")
error_response("Failed to create schedule: #{e.message}")
end
|