Class: Sidekiq::AssuredJobs::Web::OrphanedJobsManager
- Inherits:
-
Object
- Object
- Sidekiq::AssuredJobs::Web::OrphanedJobsManager
- Defined in:
- lib/sidekiq/assured_jobs/web.rb
Overview
Manager class for handling orphaned jobs operations
Class Method Summary collapse
- .bulk_delete_orphaned_jobs(jids) ⇒ Object
- .bulk_retry_orphaned_jobs(jids) ⇒ Object
- .delete_orphaned_job(jid) ⇒ Object
- .get_instances_info ⇒ Object
- .get_orphaned_job(jid) ⇒ Object
- .get_orphaned_jobs ⇒ Object
- .get_stats ⇒ Object
- .retry_orphaned_job(jid) ⇒ Object
Class Method Details
.bulk_delete_orphaned_jobs(jids) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 186 def bulk_delete_orphaned_jobs(jids) begin success_count = 0 errors = [] jids.each do |jid| result = delete_orphaned_job(jid) if result[:success] success_count += 1 else errors << "#{jid}: #{result[:error]}" end end if errors.empty? { success: true, message: "Successfully deleted #{success_count} jobs" } else { success: false, error: "Deleted #{success_count} jobs, failed: #{errors.join(', ')}" } end rescue => e { success: false, error: e. } end end |
.bulk_retry_orphaned_jobs(jids) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 162 def bulk_retry_orphaned_jobs(jids) begin success_count = 0 errors = [] jids.each do |jid| result = retry_orphaned_job(jid) if result[:success] success_count += 1 else errors << "#{jid}: #{result[:error]}" end end if errors.empty? { success: true, message: "Successfully retried #{success_count} jobs" } else { success: false, error: "Retried #{success_count} jobs, failed: #{errors.join(', ')}" } end rescue => e { success: false, error: e. } end end |
.delete_orphaned_job(jid) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 148 def delete_orphaned_job(jid) begin job_data = get_orphaned_job(jid) return { success: false, error: "Job not found" } unless job_data # Clean up tracking data cleanup_job_tracking(jid, job_data['instance_id']) { success: true } rescue => e { success: false, error: e. } end end |
.get_instances_info ⇒ Object
210 211 212 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 210 def get_instances_info AssuredJobs.get_instances_status end |
.get_orphaned_job(jid) ⇒ Object
124 125 126 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 124 def get_orphaned_job(jid) AssuredJobs.get_orphaned_job_by_jid(jid) end |
.get_orphaned_jobs ⇒ Object
120 121 122 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 120 def get_orphaned_jobs AssuredJobs.get_orphaned_jobs_info end |
.get_stats ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 214 def get_stats stats = { total_orphaned_jobs: 0, dead_instances: 0, live_instances: 0, oldest_orphaned_job: nil } orphaned_jobs = get_orphaned_jobs instances = get_instances_info stats[:total_orphaned_jobs] = orphaned_jobs.size stats[:dead_instances] = instances.count { |_, info| info[:status] == 'dead' } stats[:live_instances] = instances.count { |_, info| info[:status] == 'alive' } if orphaned_jobs.any? oldest_job = orphaned_jobs.min_by { |job| job['orphaned_at'] || Float::INFINITY } stats[:oldest_orphaned_job] = oldest_job['orphaned_duration'] if oldest_job end stats end |
.retry_orphaned_job(jid) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/sidekiq/assured_jobs/web.rb', line 128 def retry_orphaned_job(jid) begin job_data = get_orphaned_job(jid) return { success: false, error: "Job not found" } unless job_data # Clear unique-jobs lock if present AssuredJobs.clear_unique_jobs_lock(job_data) # Re-enqueue the job Sidekiq::Client.push(job_data) # Clean up tracking data cleanup_job_tracking(jid, job_data['instance_id']) { success: true } rescue => e { success: false, error: e. } end end |