Class: Sidekiq::Mcp::Tools::QueueHealthTool

Inherits:
Sidekiq::Mcp::Tool show all
Defined in:
lib/sidekiq/mcp/tools/queue_health_tool.rb

Instance Method Summary collapse

Methods inherited from Sidekiq::Mcp::Tool

arguments, #call, description, schema_to_json_schema, to_tool_definition

Instance Method Details

#perform(latency_threshold: 60, size_threshold: 100) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sidekiq/mcp/tools/queue_health_tool.rb', line 17

def perform(latency_threshold: 60, size_threshold: 100)
  queues_health = Sidekiq::Queue.all.map do |queue|
    latency = queue.latency
    size = queue.size
    
    # Determine health status
    health_issues = []
    health_issues << "High latency (#{latency.round(2)}s)" if latency > latency_threshold
    health_issues << "Large queue size (#{size} jobs)" if size > size_threshold
    
    health_status = health_issues.empty? ? "healthy" : "warning"
    health_status = "critical" if health_issues.size > 1
    
    {
      name: queue.name,
      size: size,
      latency: latency.round(2),
      health_status: health_status,
      issues: health_issues,
      recommendations: generate_recommendations(health_issues, size, latency)
    }
  end
  
  overall_health = queues_health.any? { |q| q[:health_status] == "critical" } ? "critical" : 
                  queues_health.any? { |q| q[:health_status] == "warning" } ? "warning" : "healthy"
  
  {
    overall_health: overall_health,
    thresholds: {
      latency_threshold: latency_threshold,
      size_threshold: size_threshold
    },
    queues: queues_health
  }.to_json
end