Class: Crontinel::Client
- Inherits:
-
Object
- Object
- Crontinel::Client
- Defined in:
- lib/crontinel.rb
Overview
Main Crontinel client
Constant Summary collapse
- NETWORK_ERRORS =
[ Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout, SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET ].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#cron_status(command:) ⇒ Object
Get status for a specific cron command.
-
#event(key:, message:, state: "info", metadata: {}) ⇒ Object
Send a custom event.
-
#health_check ⇒ Object
Check if Crontinel is reachable (direct HTTP, not MCP).
-
#horizon_snapshot(supervisors:, failed_jobs_per_minute: 0, paused: false) ⇒ Object
Send a Horizon snapshot.
-
#initialize(api_key: nil, endpoint: nil) {|@config| ... } ⇒ Client
constructor
A new instance of Client.
-
#recent_alerts(hours: 24) ⇒ Object
List recent alerts.
-
#scheduled_jobs ⇒ Object
List all scheduled jobs.
-
#task_failed(name:, error: nil, output: nil, duration_ms: nil) ⇒ Object
Record a scheduled task failing.
-
#task_finished(name:, output: nil, duration_ms: nil) ⇒ Object
Record a scheduled task completing successfully.
- #task_runs(name:, limit: 10) ⇒ Object
-
#task_started(name:, output: nil) ⇒ Object
── Backward-compatible aliases ───────────────────────────.
-
#worker_heartbeat(name:, status: "running", jobs_processed: nil, jobs_failed: nil, memory_mb: nil) ⇒ Object
Record a queue worker heartbeat / processed batch.
- #worker_state(name:) ⇒ Object
Constructor Details
#initialize(api_key: nil, endpoint: nil) {|@config| ... } ⇒ Client
Returns a new instance of Client.
82 83 84 85 86 87 88 |
# File 'lib/crontinel.rb', line 82 def initialize(api_key: nil, endpoint: nil) @config = Config.new @config.api_key = api_key if api_key @config.endpoint = endpoint if endpoint yield @config if block_given? @config.validate! end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
75 76 77 |
# File 'lib/crontinel.rb', line 75 def config @config end |
Instance Method Details
#cron_status(command:) ⇒ Object
Get status for a specific cron command
159 160 161 162 |
# File 'lib/crontinel.rb', line 159 def cron_status(command:) result = mcp_call("tools/call", { name: "get_cron_status", arguments: { command: command } }) (result["content"] || []).flat_map { |c| JSON.parse(c["text"]) rescue [] }.first end |
#event(key:, message:, state: "info", metadata: {}) ⇒ Object
Send a custom event
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/crontinel.rb', line 128 def event(key:, message:, state: "info", metadata: {}) mcp_call("notify/event", { key: key, message: , state: state, metadata: , ran_at: Time.now.utc.iso8601(3), app: "ruby", }) end |
#health_check ⇒ Object
Check if Crontinel is reachable (direct HTTP, not MCP)
171 172 173 174 175 176 |
# File 'lib/crontinel.rb', line 171 def health_check get("/health") true rescue NetworkError, JSON::ParserError false end |
#horizon_snapshot(supervisors:, failed_jobs_per_minute: 0, paused: false) ⇒ Object
Send a Horizon snapshot
140 141 142 143 144 145 146 147 148 |
# File 'lib/crontinel.rb', line 140 def horizon_snapshot(supervisors:, failed_jobs_per_minute: 0, paused: false) mcp_call("notify/horizon_snapshot", { supervisors: supervisors, failed_jobs_per_minute: failed_jobs_per_minute, paused: paused, ran_at: Time.now.utc.iso8601(3), app: "ruby", }) end |
#recent_alerts(hours: 24) ⇒ Object
List recent alerts
165 166 167 168 |
# File 'lib/crontinel.rb', line 165 def recent_alerts(hours: 24) result = mcp_call("tools/call", { name: "list_recent_alerts", arguments: { hours: hours } }) (result["content"] || []).flat_map { |c| JSON.parse(c["text"]) rescue [] } end |
#scheduled_jobs ⇒ Object
List all scheduled jobs
153 154 155 156 |
# File 'lib/crontinel.rb', line 153 def scheduled_jobs result = mcp_call("tools/call", { name: "list_scheduled_jobs", arguments: {} }) (result["content"] || []).flat_map { |c| JSON.parse(c["text"]) rescue [] }.map { |r| TaskRun.new(r) } end |
#task_failed(name:, error: nil, output: nil, duration_ms: nil) ⇒ Object
Record a scheduled task failing
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/crontinel.rb', line 105 def task_failed(name:, error: nil, output: nil, duration_ms: nil) mcp_call("notify/schedule_run", { command: name, exit_code: error ? 1 : 1, duration_ms: duration_ms, output: output || error, ran_at: Time.now.utc.iso8601(3), app: "ruby", }) end |
#task_finished(name:, output: nil, duration_ms: nil) ⇒ Object
Record a scheduled task completing successfully
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/crontinel.rb', line 93 def task_finished(name:, output: nil, duration_ms: nil) mcp_call("notify/schedule_run", { command: name, exit_code: 0, duration_ms: duration_ms, output: output, ran_at: Time.now.utc.iso8601(3), app: "ruby", }) end |
#task_runs(name:, limit: 10) ⇒ Object
183 184 185 |
# File 'lib/crontinel.rb', line 183 def task_runs(name:, limit: 10) scheduled_jobs.select { |r| r.name&.include?(name) }.first(limit) end |
#task_started(name:, output: nil) ⇒ Object
── Backward-compatible aliases ───────────────────────────
179 180 181 |
# File 'lib/crontinel.rb', line 179 def task_started(name:, output: nil) task_finished(name: name, output: output) end |
#worker_heartbeat(name:, status: "running", jobs_processed: nil, jobs_failed: nil, memory_mb: nil) ⇒ Object
Record a queue worker heartbeat / processed batch
117 118 119 120 121 122 123 124 125 |
# File 'lib/crontinel.rb', line 117 def worker_heartbeat(name:, status: "running", jobs_processed: nil, jobs_failed: nil, memory_mb: nil) mcp_call("notify/queue_processed", { queue: name, processed: jobs_processed || 0, failed: jobs_failed || 0, ran_at: Time.now.utc.iso8601(3), app: "ruby", }.compact) end |
#worker_state(name:) ⇒ Object
187 188 189 |
# File 'lib/crontinel.rb', line 187 def worker_state(name:) WorkerState.new("name" => name, "status" => "unknown") end |