Skip to content

Commit

Permalink
Merge pull request #9628 from alphagov/remove-csv-rake-task
Browse files Browse the repository at this point in the history
Remove rake task that relies on CSV input
  • Loading branch information
ChrisBAshton authored Nov 20, 2024
2 parents d04280a + 1659dcd commit 274bfe0
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 757 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ gem "record_tag_helper", require: false
gem "redis"
gem "responders"
gem "rinku", require: "rails_rinku"
gem "ruby-progressbar", require: false
gem "rubyzip"
gem "sentry-sidekiq"
gem "sidekiq-scheduler"
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,6 @@ DEPENDENCIES
responders
rinku
rubocop-govuk
ruby-progressbar
rubyzip
sentry-sidekiq
sidekiq-scheduler
Expand Down
72 changes: 0 additions & 72 deletions lib/reports/organisation_attachments_report.rb

This file was deleted.

41 changes: 0 additions & 41 deletions lib/reports/published_attachments_report.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/tasks/data_migrator.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "csv"

namespace :db do
namespace :data do
desc "Run all data migrations, or a specific version assigned to environment variable VERSION"
Expand Down
126 changes: 0 additions & 126 deletions lib/tasks/export.rake

This file was deleted.

129 changes: 0 additions & 129 deletions lib/tasks/publishing_api.rake
Original file line number Diff line number Diff line change
Expand Up @@ -123,135 +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 documents by content ids from CSV"
task :documents_by_content_ids_from_csv, [:csv_file_name] => :environment do |_, args|
csv = CSV.read(Rails.root.join("lib/tasks/#{args[:csv_file_name]}.csv"), headers: true)
content_ids = csv["content_id"].uniq
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 274bfe0

Please sign in to comment.