Class: Ragdoll::WorkerHealthService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ragdoll/worker_health_service.rb

Class Method Summary collapse

Class Method Details

.check_worker_healthObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/ragdoll/worker_health_service.rb', line 6

def check_worker_health
  {
    status: 'healthy',
    workers: worker_status,
    queues: queue_status,
    timestamp: Time.current
  }
rescue => e
  {
    status: 'error',
    error: e.message,
    timestamp: Time.current
  }
end

.needs_restart?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'app/services/ragdoll/worker_health_service.rb', line 21

def needs_restart?
  # Check if there are stuck jobs or workers
  stuck_jobs_count > 5 || !workers_running?
rescue
  false
end

.process_stuck_jobs!(limit = 10) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/ragdoll/worker_health_service.rb', line 28

def process_stuck_jobs!(limit = 10)
  processed = 0
  
  # Find jobs that have been processing for too long (e.g., > 1 hour)
  if defined?(SolidQueue::Job)
    stuck_jobs = SolidQueue::Job
      .where(finished_at: nil)
      .where('created_at < ?', 1.hour.ago)
      .limit(limit)
    
    stuck_jobs.each do |job|
      job.update(finished_at: Time.current)
      processed += 1
    end
  end
  
  processed
rescue => e
  ::Rails.logger.error "Failed to process stuck jobs: #{e.message}"
  0
end

.restart_workers!Object



50
51
52
53
54
55
56
57
58
# File 'app/services/ragdoll/worker_health_service.rb', line 50

def restart_workers!
  # In development, we typically don't restart workers
  # This would be implemented differently in production
  ::Rails.logger.info "Worker restart requested (no-op in development)"
  true
rescue => e
  ::Rails.logger.error "Failed to restart workers: #{e.message}"
  false
end