Skip to content

Commit

Permalink
Merge pull request #5125 from sul-dlss/new_publish_release
Browse files Browse the repository at this point in the history
Remove legacy publish shelve and all usage of stacks and purl mounts.
  • Loading branch information
jcoyne authored Jul 12, 2024
2 parents 2c3d045 + 392f0ef commit d098af3
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 248 deletions.
2 changes: 1 addition & 1 deletion app/jobs/shelve_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def perform(druid:, background_job_result:)

# Skip if publish_shelve is enabled
# However, web archive crawls still need to be shelved.
if Settings.enabled_features.publish_shelve && !WasService.crawl?(druid:)
unless WasService.crawl?(druid:)
return LogSuccessJob.perform_later(druid:,
workflow: 'accessionWF',
background_job_result:,
Expand Down
14 changes: 0 additions & 14 deletions app/services/delete_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class DeleteService
# - Removes content from dor workspace
# - Removes content from assembly workspace
# - Removes content from sdr export area
# - Removes content from stacks
# - Removes content from purl
# - Removes active workflows
# @param [Cocina::Models::DRO|AdminPolicy||Collection] cocina object wish to remove
def self.destroy(cocina_object, user_name:)
Expand All @@ -22,8 +20,6 @@ def initialize(cocina_object, user_name)

def destroy
CleanupService.cleanup_by_druid druid
cleanup_stacks
cleanup_purl_doc_cache
remove_active_workflows
delete_from_dor
EventFactory.create(druid:, event_type: 'delete', data: { request: cocina_object.to_h, source_id: cocina_object&.identification&.sourceId, user_name: })
Expand All @@ -33,16 +29,6 @@ def destroy

attr_reader :cocina_object, :user_name

def cleanup_stacks
stacks_druid = DruidTools::StacksDruid.new(druid, Settings.stacks.local_stacks_root)
PruneService.new(druid: stacks_druid).prune!
end

def cleanup_purl_doc_cache
purl_druid = DruidTools::PurlDruid.new(druid, Settings.stacks.local_document_cache_root)
PruneService.new(druid: purl_druid).prune!
end

def remove_active_workflows
WorkflowClientFactory.build.delete_all_workflows(pid: druid)
end
Expand Down
44 changes: 4 additions & 40 deletions app/services/publish/metadata_transfer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ def initialize(cocina_object, workflow:)
# Appends contentMetadata file resources from the source objects to this object
def publish
republish_collection_members!
return unpublish unless discoverable?

if Settings.enabled_features.publish_shelve
publish_shelve
republish_virtual_object_constituents!
else
transfer_metadata
publish_notify_on_success
end
return publish_delete_on_success unless discoverable?

publish_shelve
republish_virtual_object_constituents!
release_tags_on_success
end

Expand All @@ -41,16 +36,6 @@ def druid
cocina_object.externalIdentifier
end

def transfer_metadata
transfer_to_document_store(public_cocina.to_json, 'cocina.json')
end

# Clear out the document cache for this item
def unpublish
PruneService.new(druid: purl_druid).prune!
publish_delete_on_success
end

def discoverable?
cocina_object.access.view != 'dark'
end
Expand All @@ -71,27 +56,6 @@ def republish_virtual_object_constituents!
end
end

# Create a file inside the content directory under the stacks.local_document_cache_root
# @param [String] content The contents of the file to be created
# @param [String] filename The name of the file to be created
# @return [void]
def transfer_to_document_store(content, filename)
new_file = File.join(purl_druid.content_dir, filename)
Rails.logger.debug("[Publish][#{cocina_object.externalIdentifier}] Writing #{new_file}")
File.write(new_file, content)
end

def purl_druid
@purl_druid ||= DruidTools::PurlDruid.new cocina_object.externalIdentifier, Settings.stacks.local_document_cache_root
end

##
# When publishing a PURL, we notify purl-fetcher of changes.
#
def publish_notify_on_success
PurlFetcher::Client::LegacyPublish.publish(cocina: public_cocina)
end

def release_tags_on_success
tags = ReleaseTagService.for_public_metadata(cocina_object: public_cocina)
actions = { index: [], delete: [] }.tap do |releases|
Expand Down
4 changes: 1 addition & 3 deletions app/services/shelving_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def base_inventory(subset)
def stacks_location
# Currently the best know way to identify objects like this is to see if the wasCrawlPreassemblyWF workflow is present.
# If this condition is met, then shelf to /web-archiving-stacks/data/collections/<collection_id>, where collection_id is the unnamespaced druid of the (first) collection.
return was_stack_location if was?

Settings.stacks.local_stacks_root
was_stack_location
end

def was?
Expand Down
3 changes: 0 additions & 3 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ enabled_features:
create_ur_admin_policy: false
datacite_update: false
orcid_update: true
publish_shelve: false

# Ur Admin Policy
ur_admin_policy:
Expand All @@ -16,8 +15,6 @@ ur_admin_policy:
stacks:
document_cache_host: 'purl-test.stanford.edu'
local_workspace_root: '/dor/workspace'
local_stacks_root: '/stacks'
local_document_cache_root: '/purl/document_cache'
transfer_stage_root: '/transfer-stage'

# Suri
Expand Down
79 changes: 12 additions & 67 deletions spec/jobs/shelve_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,22 @@
let(:druid) { 'druid:mk420bs7601' }
let(:result) { create(:background_job_result) }
let(:cocina_object) { instance_double(Cocina::Models::DRO) }
let(:valid) { true }
let(:invalid_filenames) { [] }

before do
allow(CocinaObjectStore).to receive(:find).with(druid).and_return(cocina_object)
allow(result).to receive(:processing!)
allow(EventFactory).to receive(:create)
allow(ShelvingService).to receive(:shelve)
allow(LogSuccessJob).to receive(:perform_later)
end

context 'with no errors' do
context 'when not a WAS crawl' do
before do
allow(ShelvingService).to receive(:shelve)
allow(LogSuccessJob).to receive(:perform_later)
perform
end

it 'marks the job as processing' do
expect(result).to have_received(:processing!).once
end

it 'invokes the ShelvingService' do
expect(ShelvingService).to have_received(:shelve).with(cocina_object).once
allow(WasService).to receive(:crawl?).with(druid:).and_return(false)
end

it 'marks the job as complete' do
expect(EventFactory).to have_received(:create)
it 'skips shelving' do
perform
expect(ShelvingService).not_to have_received(:shelve)
expect(LogSuccessJob).to have_received(:perform_later)
.with(druid:,
background_job_result: result,
Expand All @@ -42,64 +32,19 @@
end
end

context 'with errors returned by ShelvingService' do
let(:error_message) { "file isn't where we looked" }

context 'when a WAS crawl' do
before do
allow(ShelvingService).to receive(:shelve).and_raise(LegacyShelvableFilesStager::FileNotFound, error_message)
allow(LogFailureJob).to receive(:perform_later)
allow(WasService).to receive(:crawl?).with(druid:).and_return(true)
end

it 'marks the job as errored' do
it 'performs shelving' do
perform
expect(result).to have_received(:processing!).once
expect(ShelvingService).to have_received(:shelve).with(cocina_object).once
expect(LogFailureJob).to have_received(:perform_later)
expect(LogSuccessJob).to have_received(:perform_later)
.with(druid:,
background_job_result: result,
workflow: 'accessionWF',
workflow_process: 'shelve',
output: { errors: [{ detail: error_message, title: 'Unable to shelve files' }] })
end
end

context 'when publish_shelve feature flag is enabled' do
before do
allow(Settings.enabled_features).to receive(:publish_shelve).and_return(true)
allow(ShelvingService).to receive(:shelve)
allow(LogSuccessJob).to receive(:perform_later)
end

context 'when not a WAS crawl' do
before do
allow(WasService).to receive(:crawl?).with(druid:).and_return(false)
end

it 'skips shelving' do
perform
expect(ShelvingService).not_to have_received(:shelve)
expect(LogSuccessJob).to have_received(:perform_later)
.with(druid:,
background_job_result: result,
workflow: 'accessionWF',
workflow_process: 'shelve')
end
end

context 'when a WAS crawl' do
before do
allow(WasService).to receive(:crawl?).with(druid:).and_return(true)
end

it 'performs shelving' do
perform
expect(ShelvingService).to have_received(:shelve).with(cocina_object).once
expect(LogSuccessJob).to have_received(:perform_later)
.with(druid:,
background_job_result: result,
workflow: 'accessionWF',
workflow_process: 'shelve')
end
workflow_process: 'shelve')
end
end
end
3 changes: 0 additions & 3 deletions spec/services/cleanup_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@
let(:workspace_dir) { File.join(fixture_dir, 'workspace') }
let(:export_dir) { File.join(fixture_dir, 'export') }
let(:assembly_dir) { File.join(fixture_dir, 'assembly') }
let(:stacks_dir) { File.join(fixture_dir, 'stacks') }

let(:druid1) { 'druid:cd456ef7890' }
let(:druid2) { 'druid:cd456gh1234' }
Expand All @@ -214,13 +213,11 @@
local_export_home: export_dir,
local_assembly_root: assembly_dir
)
allow(Settings.stacks).to receive(:local_stacks_root).and_return(stacks_dir)

FileUtils.mkdir fixture_dir
FileUtils.mkdir workspace_dir
FileUtils.mkdir export_dir
FileUtils.mkdir assembly_dir
FileUtils.mkdir stacks_dir
end

after do
Expand Down
25 changes: 0 additions & 25 deletions spec/services/delete_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,6 @@
end
end

describe '#cleanup_stacks' do
let(:fixture_dir) { '/tmp/cleanup-spec' }
let(:stacks_dir) { File.join(fixture_dir, 'stacks') }
let(:stacks_druid) { DruidTools::StacksDruid.new(druid, Settings.stacks.local_stacks_root) }

before do
allow(Settings.stacks).to receive(:local_stacks_root).and_return(stacks_dir)
FileUtils.mkdir fixture_dir
FileUtils.mkdir stacks_dir

stacks_druid.mkdir

File.write(File.join(stacks_druid.path, 'tempfile'), 'junk')
end

after do
FileUtils.rm_rf fixture_dir
end

it 'prunes the item from the local stacks root' do
expect { service.send(:cleanup_stacks) }.to change { File.exist?(stacks_druid.path) }
.from(true).to(false)
end
end

describe '#delete_from_dor' do
before do
create(:repository_object, external_identifier: druid)
Expand Down
Loading

0 comments on commit d098af3

Please sign in to comment.