From 5e43c01e7b5b1d867149a8fae8973ad5004aef93 Mon Sep 17 00:00:00 2001 From: Darren Hardy Date: Mon, 15 Aug 2016 14:27:51 -0700 Subject: [PATCH] Adds publish_notify_on_success to touch change files in the PURL filesystem --- lib/dor/models/publishable.rb | 12 ++++++++++++ spec/dor/publishable_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/dor/models/publishable.rb b/lib/dor/models/publishable.rb index 4aba4f20..2bb624a1 100644 --- a/lib/dor/models/publishable.rb +++ b/lib/dor/models/publishable.rb @@ -1,4 +1,5 @@ require 'dor/datastreams/content_metadata_ds' +require 'fileutils' module Dor module Publishable @@ -61,6 +62,7 @@ def publish_metadata end DigitalStacksService.transfer_to_document_store(pid, public_xml, 'public') DigitalStacksService.transfer_to_document_store(pid, generate_public_desc_md, 'mods') if metadata_format == 'mods' + publish_notify_on_success else # Clear out the document cache for this item DigitalStacksService.prune_purl_dir pid @@ -74,5 +76,15 @@ def publish_metadata_remotely endpoint.post '' endpoint.url end + + ## + # When publishing a PURL, we drop a `aa11bb2222` file into the `local_recent_changes` folder + # to notify other applications watching the filesystem (i.e., purl-fetcher). + # @param [String] `local_recent_changes` usually `/purl/recent_changes` + def publish_notify_on_success(local_recent_changes = Config.stacks.local_recent_changes) + raise ArgumentError, "Missing local_recent_changes directory: #{local_recent_changes}" unless File.directory?(local_recent_changes) + id = pid.gsub(/^druid:/, '') + FileUtils.touch(File.join(local_recent_changes, id)) + end end end diff --git a/spec/dor/publishable_spec.rb b/spec/dor/publishable_spec.rb index 480621c6..cdc939f9 100644 --- a/spec/dor/publishable_spec.rb +++ b/spec/dor/publishable_spec.rb @@ -327,6 +327,7 @@ class ItemizableItem < ActiveFedora::Base expect(Dor::DigitalStacksService).to receive(:transfer_to_document_store).with('druid:ab123cd4567', /