Class: Sidekiq::Mcp::Tools::JobClassStatsTool
- Inherits:
-
Sidekiq::Mcp::Tool
- Object
- Sidekiq::Mcp::Tool
- Sidekiq::Mcp::Tools::JobClassStatsTool
- Defined in:
- lib/sidekiq/mcp/tools/job_class_stats_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 ⇒ Object
16 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 52 |
# File 'lib/sidekiq/mcp/tools/job_class_stats_tool.rb', line 16 def perform stats = {} # Get stats from retry set Sidekiq::RetrySet.new.each do |job| klass = job.klass stats[klass] ||= { retry_count: 0, failed_count: 0, total_retries: 0 } stats[klass][:retry_count] += 1 stats[klass][:total_retries] += (job["retry_count"] || 0) end # Get stats from dead set Sidekiq::DeadSet.new.each do |job| klass = job.klass stats[klass] ||= { retry_count: 0, failed_count: 0, total_retries: 0 } stats[klass][:failed_count] += 1 end # Get stats from queues Sidekiq::Queue.all.each do |queue| queue.each do |job| klass = job.klass stats[klass] ||= { retry_count: 0, failed_count: 0, total_retries: 0, enqueued_count: 0 } stats[klass][:enqueued_count] = (stats[klass][:enqueued_count] || 0) + 1 end end # Calculate error rates stats.each do |klass, data| total_jobs = (data[:retry_count] || 0) + (data[:failed_count] || 0) + (data[:enqueued_count] || 0) error_count = (data[:retry_count] || 0) + (data[:failed_count] || 0) data[:error_rate] = total_jobs > 0 ? (error_count.to_f / total_jobs * 100).round(2) : 0 data[:total_jobs] = total_jobs end stats.to_json end |