Module: Desiru::Jobs::Retriable
- Included in:
- RetriableJob
- Defined in:
- lib/desiru/jobs/retriable.rb
Overview
Mixin for adding advanced retry capabilities to jobs
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#perform_with_retries(*args) ⇒ Object
Wrap job execution with retry logic.
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/desiru/jobs/retriable.rb', line 9 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#perform_with_retries(*args) ⇒ Object
Wrap job execution with retry logic
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/desiru/jobs/retriable.rb', line 36 def perform_with_retries(*args) retry_count = 0 job_id = args.first if args.first.is_a?(String) begin # Track retry count in job result if persistence is enabled if job_id && respond_to?(:persistence_enabled?) && persistence_enabled? update_retry_count(job_id, retry_count) end perform_without_retries(*args) rescue StandardError => e policy = self.class.retry_policy if policy.should_retry?(retry_count, e) retry_count += 1 delay = policy.retry_delay(retry_count) log_retry(e, retry_count, delay) # Schedule retry with delay self.class.perform_in(delay, *args) # Don't re-raise - we've scheduled a retry nil else # Max retries exceeded or non-retriable error log_retry_failure(e, retry_count) # Mark job as failed if persistence is enabled persist_error_to_db(job_id, e, e.backtrace) if job_id && respond_to?(:persist_error_to_db) # Re-raise to let Sidekiq handle it raise end end end |