123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::DestroyAssociationAsyncJob

Overview

Job to destroy the records associated with a destroyed record in background.

Constant Summary

::ActiveSupport::Callbacks - Included

CALLBACK_FILTER_TYPES

::ActiveJob::Exceptions - Included

JITTER_DEFAULT

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

::ActiveJob::Base - Inherited

::ActiveJob::Logging - Included

::ActiveJob::Callbacks - Included

::ActiveJob::Execution - Included

::ActiveJob::Core - Included

#arguments

Job arguments.

#enqueue_error

Track any exceptions raised by the backend so callers can inspect the errors.

#enqueued_at

Track when a job was enqueued.

#exception_executions

::Hash that contains the number of times this job handled errors for each specific retry_on declaration.

#executions

Number of times this job has been executed (which increments on every retry, like after an exception).

#job_id

Job Identifier.

#locale

I18n.locale to be used during the job.

#priority=

Priority that the job will have (lower is more priority).

#provider_job_id

ID optionally provided by adapter.

#queue_name=

Queue in which the job will reside.

#scheduled_at

::Time when the job should be performed.

#serialized_arguments=, #successfully_enqueued?,
#timezone

Timezone to be used during the job.

#arguments_serialized?,
#successfully_enqueued=

Track whether the adapter received the job successfully.

Instance Method Summary

::ActiveJob::Logging - Included

::ActiveJob::Instrumentation - Included

::ActiveJob::Exceptions - Included

::ActiveSupport::Callbacks - Included

#run_callbacks

Runs the callbacks for the given event.

#halted_callback_hook

A hook invoked every time a before callback is halted.

::ActiveJob::Execution - Included

#perform,
#perform_now

Performs the job immediately.

#_perform_job

::ActiveSupport::Rescuable - Included

#rescue_with_handler

Delegates to the class method, but uses the instance as the subject for rescue_from handlers (method calls, instance_exec blocks).

#handler_for_rescue

Internal handler lookup.

::ActiveJob::Enqueuing - Included

#enqueue

Enqueues the job to be performed by the queue adapter.

#raw_enqueue

::ActiveJob::QueuePriority - Included

#priority

Returns the priority that the job will be created with.

::ActiveJob::QueueName - Included

#queue_name

Returns the name of the queue the job will be run on.

::ActiveJob::Core - Included

#deserialize

Attaches the stored job data to the current instance.

#initialize

Creates a new job instance.

#serialize

Returns a hash with the job data that can safely be passed to the queuing adapter.

#deserialize_arguments, #deserialize_arguments_if_needed, #serialize_arguments, #serialize_arguments_if_needed,
#set

Configures the job with the given options.

Instance Method Details

#owner_destroyed?(owner, ensuring_owner_was_method) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/destroy_association_async_job.rb', line 34

def owner_destroyed?(owner, ensuring_owner_was_method)
  !owner || (ensuring_owner_was_method && owner.public_send(ensuring_owner_was_method))
end

#perform(owner_model_name: nil, owner_id: nil, association_class: nil, association_ids: nil, association_primary_key_column: nil, ensuring_owner_was_method: nil)

[ GitHub ]

  
# File 'activerecord/lib/active_record/destroy_association_async_job.rb', line 15

def perform(
  owner_model_name: nil, owner_id: nil,
  association_class: nil, association_ids: nil, association_primary_key_column: nil,
  ensuring_owner_was_method: nil
)
  association_model = association_class.constantize
  owner_class = owner_model_name.constantize
  owner = owner_class.find_by(owner_class.primary_key => [owner_id])

  if !owner_destroyed?(owner, ensuring_owner_was_method)
    raise DestroyAssociationAsyncError, "owner record not destroyed"
  end

  association_model.where(association_primary_key_column => association_ids).find_each do |r|
    r.destroy
  end
end