Skip to content

Add after_destroy callbacks on CoreFile and Project to clean up tapas-xq #55

@candyhazlett

Description

@candyhazlett

Background

CoreFilesController#destroy and ProjectsController#destroy destroy records in Rails but never notify tapas-xq. TEI, MODS, and TFE records accumulate in BaseX indefinitely.

Work required

app/models/core_file.rb

Add after_destroy :enqueue_tapas_xq_deletion and a private method:

def enqueue_tapas_xq_deletion
  return unless tapas_xq_doc_id.present?

  DeleteFromTapasXqJob.perform_later(
    project_id: tapas_xq_project_id,
    doc_id: tapas_xq_doc_id
  )
end

The tapas_xq_doc_id guard ensures files that were never successfully uploaded (processing failed before completion) don't trigger a pointless deletion attempt. The after_destroy callback runs after the DB row is removed but the in-memory object retains its attribute values, so reading tapas_xq_doc_id here is safe.

app/models/project.rb

Add after_destroy :enqueue_tapas_xq_project_deletion and a private method:

def enqueue_tapas_xq_project_deletion
  DeleteProjectFromTapasXqJob.perform_later(id.to_s)
end

Note: id is available on the in-memory object after after_destroy runs.

Dependencies

  • DeleteFromTapasXqJob and DeleteProjectFromTapasXqJob must exist first

Tests

Add to spec/models/core_file_spec.rb and spec/requests/core_files_spec.rb and spec/requests/projects_spec.rb. See testing plan doc for specific examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions