Skip to content

Commit

Permalink
Remove obsolete 'bulk_republish' rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBAshton committed Nov 19, 2024
1 parent 12cc628 commit 1659dcd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 389 deletions.
116 changes: 0 additions & 116 deletions lib/tasks/publishing_api.rake
Original file line number Diff line number Diff line change
Expand Up @@ -123,122 +123,6 @@ namespace :publishing_api do
end
end

namespace :bulk_republish do
desc "Republish all About pages"
task all_about_pages: :environment do
about_us_pages = Organisation.all.map(&:about_us).compact
count = about_us_pages.count
puts "# Sending #{count} 'about us' pages to Publishing API"
about_us_pages.each_with_index do |about_us_page, i|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue(
"bulk_republishing",
about_us_page.document_id,
true,
)
puts "Queuing #{i}-#{i + 99} of #{count} items" if (i % 100).zero?
end
puts "Finished queuing items for Publishing API"
end

desc "Republish all documents with draft editions"
task all_drafts: :environment do
editions = Edition.in_pre_publication_state.includes(:document)

puts "Enqueueing #{editions.count} documents"
editions.find_each do |edition|
document_id = edition.document.id
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document_id, true)
end
puts "Finished enqueueing items for Publishing API"
end

desc "Republish all editions which have attachments to the Publishing API"
task editions_with_attachments: :environment do
editions = Edition.publicly_visible.where(
id: Attachment.where(attachable_type: "Edition").select("attachable_id"),
)

editions.joins(:document).distinct.pluck("documents.id").each do |document_id|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document_id, true)
end
end

desc "⚠️ WARNING: this rake task republishes **all** documents with HTML attachments (this can block publishing for > 1 hour) ⚠️. Republish all documents with HTML attachments to the Publishing API."
task html_attachments: :environment do
document_ids = Edition
.publicly_visible
.where(id: HtmlAttachment.where(attachable_type: "Edition").select(:attachable_id))
.pluck(:document_id)
document_ids.each do |document_id|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document_id, true)
end
end

desc "Republish all draft editions with HTML attachments to the Publishing API"
task drafts_with_html_attachments: :environment do
document_ids = Edition
.in_pre_publication_state
.where(id: HtmlAttachment.where(attachable_type: "Edition").select(:attachable_id))
.pluck(:document_id)
document_ids.each do |document_id|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document_id, true)
end
end

desc "Republish all documents of a given type, e.g. 'NewsArticle'"
task :document_type, [:document_type] => :environment do |_, args|
begin
document_type = args[:document_type].constantize
rescue NameError
abort "Unknown document type #{args[:document_type]}\nCheck the GOV.UK developer documentation for a list of acceptable document types: https://docs.publishing.service.gov.uk/manual/republishing-content.html#whitehall"
end

documents = document_type.all
puts "Enqueueing #{documents.count} documents"
documents.find_each do |document|
if document.respond_to?(:publish_to_publishing_api)
Whitehall::PublishingApi.bulk_republish_async(document) if document.can_publish_to_publishing_api?
else
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document.document_id, true)
end
end
puts "Finished enqueueing items for Publishing API"
end

desc "Republish all documents of a given organisation"
task :by_organisation, [:organisation_slug] => :environment do |_, args|
org = Organisation.find_by(slug: args[:organisation_slug])
editions = Edition.latest_edition.in_organisation(org)
puts "Enqueueing #{editions.count} documents"
editions.find_each do |edition|
document = edition.document
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document.id, true)
end
puts "Finished enqueueing items for Publishing API"
end

desc "Republish documents by content id"
task :documents_by_content_ids, %w[content_ids] => :environment do |_, args|
content_ids = args[:content_ids].split
document_ids = Document.where(content_id: content_ids).pluck(:id)

puts "Bulk republishing #{document_ids.count} documents"

document_ids.each do |id|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", id, true)
end
end

desc "Republish all documents"
task all_documents: :environment do
puts "Enqueueing #{Document.count} documents"
Document.find_each do |document|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document.id, true)
end
puts "Finished enqueueing items for Publishing API"
end
end

namespace :unpublish do
desc "Manually unpublish content with a redirect"
# This task is for unpublishing Whitehall managed content where
Expand Down
Loading

0 comments on commit 1659dcd

Please sign in to comment.