Skip to content

Commit

Permalink
Merge pull request #3188 from alphagov/publish-extra-logging
Browse files Browse the repository at this point in the history
Add tons of debug logging to publish command
  • Loading branch information
kevindew authored Mar 7, 2025
2 parents 6855ad5 + f297685 commit 211323f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/commands/v2/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module Commands
module V2
class Publish < BaseCommand
def call
Rails.logger.debug("Starting publish command")
validate
Rails.logger.debug("Completed validation, starting publish")
publish_edition
Rails.logger.debug("Completed publish, sending downstream")
after_transaction_commit { send_downstream }

Success.new({ content_id: })
Expand All @@ -15,7 +18,7 @@ def call

def publish_edition
delete_change_notes unless UPDATE_TYPES_WITH_CHANGE_NOTES.include?(update_type)
previous_edition.supersede if previous_edition
supersede_previous_edition if previous_edition

unless edition.pathless?
redirect_old_base_path
Expand All @@ -26,7 +29,10 @@ def publish_edition
set_publishing_request_id
set_update_type
set_timestamps

Rails.logger.debug("Publishing Edition")
edition.publish

remove_draft_access
create_publish_action
create_change_note if payload[:update_type].present?
Expand All @@ -41,14 +47,20 @@ def orphaned_content_ids
end

def create_publish_action
Rails.logger.debug("Creating publish action")

Action.create_publish_action(edition, document.locale, event)
end

def create_change_note
Rails.logger.debug("Creating change note")

ChangeNote.create_from_edition(payload, edition)
end

def remove_draft_access
Rails.logger.debug("Removing draft access")

edition.update!(auth_bypass_ids: []) if edition.auth_bypass_ids.any?
AccessLimit.where(edition:).delete_all
end
Expand All @@ -74,6 +86,8 @@ def previous_edition
def redirect_old_base_path
return unless previous_edition

Rails.logger.debug("Redirecting old base path")

previous_base_path = previous_edition.base_path

if previous_base_path != edition.base_path
Expand Down Expand Up @@ -116,9 +130,15 @@ def validate_update_type
end

def delete_change_notes
Rails.logger.debug("Deleting change notes")
ChangeNote.where(edition:).delete_all
end

def supersede_previous_edition
Rails.logger.debug("Supersedeing previous edition")
previous_edition.supersede
end

def document
@document ||= Document.find_or_create_locked(
content_id: payload[:content_id],
Expand Down Expand Up @@ -147,6 +167,8 @@ def already_published?
end

def clear_published_items_of_same_locale_and_base_path
Rails.logger.debug("Clear published items of same locale and base path")

SubstitutionHelper.clear!(
new_item_document_type: edition.document_type,
new_item_content_id: document.content_id,
Expand All @@ -162,6 +184,8 @@ def clear_published_items_of_same_locale_and_base_path
def clear_published_item_of_different_locale_but_matching_base_path
return unless edition.base_path

Rails.logger.debug("Clearing published item of different locale but matching base path")

published_edition_for_different_locale = Edition.with_document.where(
documents: {
content_id: document.content_id,
Expand All @@ -183,6 +207,8 @@ def clear_published_item_of_different_locale_but_matching_base_path
end

def set_timestamps
Rails.logger.debug("Setting timestamps")

Edition::Timestamps.live_transition(edition, update_type, previous_edition)
end

Expand All @@ -191,6 +217,8 @@ def default_datetime
end

def set_publishing_request_id
Rails.logger.debug("Setting publishing request id")

edition.update!(
publishing_request_id: GdsApi::GovukHeaders.headers[:govuk_request_id],
)
Expand All @@ -199,6 +227,8 @@ def set_publishing_request_id
def set_update_type
return if edition.update_type

Rails.logger.debug("Setting update type")

edition.update!(update_type:)
end

Expand Down

0 comments on commit 211323f

Please sign in to comment.