Class: Delayed::Backend::ActiveRecord::Job::Failed

Inherits:
Delayed::Backend::ActiveRecord::Job show all
Includes:
Base
Defined in:
lib/delayed/backend/active_record.rb

Constant Summary

Constants included from Base

Base::ON_HOLD_BLOCKER, Base::ON_HOLD_COUNT, Base::ON_HOLD_LOCKED_BY

Instance Attribute Summary

Attributes inherited from Delayed::Backend::ActiveRecord::Job

#enqueue_result

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#batch?, #expired?, #failed?, #full_name, #hold!, included, #inferred_max_attempts, #initialize_defaults, #invoke_job, #locked?, #name, #on_hold?, #payload_object, #payload_object=, #permanent_failure, #reschedule, #reschedule_at, #unhold!, #unlock

Methods inherited from Delayed::Backend::ActiveRecord::Job

advisory_lock, all_available, apply_temp_strand!, attempt_advisory_lock, bulk_update, by_priority, clear_locks!, create, #create_and_lock!, create_singleton, current, #destroy, #fail!, failed, find_available, future, get_and_lock_next_available, jobs_count, list_jobs, #lock_strand_on_create, maybe_silence_periodic_log, n_strand_options, prefetch_jobs_lock_name, processes_locked_locally, ready_to_run, reconnect!, running, running_jobs, scope_for_flavor, #single_step_create, strand_size, tag_counts, #transfer_lock!, unlock, unlock_orphaned_prefetched_jobs

Methods inherited from ActiveRecord::Base

#encode_with, load_for_delayed_job

Class Method Details

.cleanup_old_jobs(before_date, batch_size: 10_000) ⇒ Object



649
650
651
# File 'lib/delayed/backend/active_record.rb', line 649

def self.cleanup_old_jobs(before_date, batch_size: 10_000)
  where("failed_at < ?", before_date).in_batches(of: batch_size).delete_all
end

Instance Method Details

#requeue!Object



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/delayed/backend/active_record.rb', line 653

def requeue!
  attrs = attributes.except("id",
                            "last_error",
                            "locked_at",
                            "failed_at",
                            "locked_by",
                            "original_job_id",
                            "requeued_job_id")
  self.class.transaction do
    job = nil
    Delayed::Worker.lifecycle.run_callbacks(:create, attrs.merge("payload_object" => payload_object)) do
      job = Job.create(attrs)
    end
    self.requeued_job_id = job.id
    save!
    JobTracking.job_created(job)
    job
  end
end