Class: SharedTools::Tools::CronTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::CronTool
- Defined in:
- lib/shared_tools/tools/cron_tool.rb
Overview
A tool for parsing, validating, and explaining cron expressions. Supports standard 5-field cron format (minute, hour, day of month, month, day of week).
Constant Summary collapse
- DAYS_OF_WEEK =
{ 'SUN' => 0, 'MON' => 1, 'TUE' => 2, 'WED' => 3, 'THU' => 4, 'FRI' => 5, 'SAT' => 6 }.freeze
- MONTHS =
{ 'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6, 'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' => 10, 'NOV' => 11, 'DEC' => 12 }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(action:, expression: nil, description: nil, count: nil) ⇒ Hash
Execute cron action.
-
#initialize(logger: nil) ⇒ CronTool
constructor
A new instance of CronTool.
Constructor Details
#initialize(logger: nil) ⇒ CronTool
Returns a new instance of CronTool.
95 96 97 |
# File 'lib/shared_tools/tools/cron_tool.rb', line 95 def initialize(logger: nil) @logger = logger || RubyLLM.logger end |
Class Method Details
.name ⇒ Object
16 |
# File 'lib/shared_tools/tools/cron_tool.rb', line 16 def self.name = 'cron' |
Instance Method Details
#execute(action:, expression: nil, description: nil, count: nil) ⇒ Hash
Execute cron action
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/shared_tools/tools/cron_tool.rb', line 106 def execute(action:, expression: nil, description: nil, count: nil) @logger.info("CronTool#execute action=#{action.inspect}") case action.to_s.downcase when 'parse' parse_expression(expression) when 'validate' validate_expression(expression) when 'next' next_executions(expression, count || 5) when 'generate' generate_expression(description) else { success: false, error: "Unknown action: #{action}. Valid actions are: parse, validate, next, generate" } end rescue => e @logger.error("CronTool error: #{e.message}") { success: false, error: e. } end |