Skip to content

Commit

Permalink
Merge pull request #1242 from alphagov/remove-icinga-reference
Browse files Browse the repository at this point in the history
Simplify Importer Rake Tasks icinga reference
  • Loading branch information
KludgeKML authored Feb 21, 2024
2 parents a487a7c + e5d4eb2 commit fefb82e
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 117 deletions.
4 changes: 0 additions & 4 deletions app/lib/local_links_manager/import/interactions_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class InteractionsImporter
"Identifier" => :lgil_code,
}.freeze

def self.import
new.import_records
end

def initialize(
csv_downloader = CsvDownloader.new(CSV_URL, header_conversions: FIELD_NAME_CONVERSIONS),
import_comparer = ImportComparer.new
Expand Down
4 changes: 0 additions & 4 deletions app/lib/local_links_manager/import/publishing_api_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
module LocalLinksManager
module Import
class PublishingApiImporter
def self.import
new.import_data
end

def initialize(import_comparer = ImportComparer.new)
@comparer = import_comparer
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class ServiceInteractionsImporter
"Mapped identifier" => :lgil_code,
}.freeze

def self.import
new.import_records
end

def initialize(
csv_downloader = CsvDownloader.new(CSV_URL, header_conversions: FIELD_NAME_CONVERSIONS),
import_comparer = ImportComparer.new
Expand Down
4 changes: 0 additions & 4 deletions app/lib/local_links_manager/import/services_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class ServicesImporter
"Identifier" => :lgsl_code,
}.freeze

def self.import
new.import_records
end

def initialize(
csv_downloader = CsvDownloader.new(CSV_URL, header_conversions: FIELD_NAME_CONVERSIONS),
import_comparer = ImportComparer.new
Expand Down
4 changes: 0 additions & 4 deletions app/lib/local_links_manager/import/services_tier_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class ServicesTierImporter
"Providing Tier" => :tier,
}.freeze

def self.import
new.import_tiers
end

def initialize(csv_downloader = CsvDownloader.new(CSV_URL, header_conversions: FIELD_NAME_CONVERSIONS))
@csv_downloader = csv_downloader
end
Expand Down
12 changes: 0 additions & 12 deletions app/lib/services.rb

This file was deleted.

26 changes: 0 additions & 26 deletions config/brakeman.ignore

This file was deleted.

6 changes: 0 additions & 6 deletions lib/tasks/check-links/link_checker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@ require_relative "../../../app/lib/local_links_manager/check_links/link_status_r

desc "Check all links for enabled services"
task "check-links": :environment do
service_desc = "Local Links Manager link checker rake task"
LocalLinksManager::DistributedLock.new("check-links").lock(
lock_obtained: lambda {
begin
Rails.logger.info("Lock obtained, starting link checker")
Services.icinga_check(service_desc, "true", "Lock obtained, starting link checker")
LocalLinksManager::CheckLinks::LinkStatusRequester.new.call
Rails.logger.info("Link checker completed")
# Flag nagios that this server's instance succeeded to stop lingering failures
Services.icinga_check(service_desc, "true", "Success")
rescue StandardError => e
Rails.logger.error("Error while running link checker\n#{e}")
Services.icinga_check(service_desc, "false", e.to_s)
raise e
end
},
lock_not_obtained: lambda {
Rails.logger.info("Unable to lock")
Services.icinga_check(service_desc, "true", "Unable to lock")
},
)
end
Expand Down
5 changes: 0 additions & 5 deletions lib/tasks/export/analytics_bad_links_exporter.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@ namespace :export do
desc "Export bad links status to Google Analytics"
task "bad_links": :environment do
if ENV["RUN_LINK_GA_EXPORT"].present? && ENV["RUN_LINK_GA_EXPORT"] == "true"
service_desc = "Export bad links status to Google Analytics"
LocalLinksManager::DistributedLock.new("bad-links-analytics-export").lock(
lock_obtained: lambda {
begin
Rails.logger.info("Starting link exporter")
Services.icinga_check(service_desc, "true", "Exporting list of bad links to Google Analytics")

LocalLinksManager::Export::AnalyticsExporter.export

Rails.logger.info("Bad links export to GA has completed")
Services.icinga_check(service_desc, "true", "Success")
rescue StandardError => e
Rails.logger.error("Error while running link exporter\n#{e}")
Services.icinga_check(service_desc, "false", e.to_s)
raise e
end
},
lock_not_obtained: lambda {
Services.icinga_check(service_desc, "true", "Unable to lock")
},
)
end
Expand Down
19 changes: 6 additions & 13 deletions lib/tasks/export/link_exporter.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ namespace :export do
namespace :links do
desc "Export links to CSV"
task "all": :environment do
service_desc = "Export links to CSV from local-links-manager"
begin
Rails.logger.info("Starting link exporter")
Services.icinga_check(service_desc, "true", "Starting link exporter")

LocalLinksManager::Export::LinksExporter.export_links
Rails.logger.info("Link export to CSV completed")
Services.icinga_check(service_desc, "true", "Success")
rescue StandardError => e
Rails.logger.error("Error while running link exporter\n#{e}")
Services.icinga_check(service_desc, "false", e.to_s)
raise e
end
Rails.logger.info("Starting link exporter")
LocalLinksManager::Export::LinksExporter.export_links
Rails.logger.info("Link export to CSV completed")
rescue StandardError => e
Rails.logger.error("Error while running link exporter\n#{e}")
raise e
end

# This task duplicates functionality in `export:links:all`, except uploads
Expand Down
6 changes: 1 addition & 5 deletions lib/tasks/import/google_analytics.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ require_relative "../../../app/lib/local_links_manager/import/analytics_importer
namespace :import do
desc "Imports analytics so that links can be prioritised by usage"
task google_analytics: :environment do
service_desc = "Import Google Analytics to Local Links Manager"
LocalLinksManager::DistributedLock.new("analytics-import").lock(
lock_obtained: lambda {
begin
response = LocalLinksManager::Import::AnalyticsImporter.import
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::AnalyticsImporter.import
rescue StandardError => e
Services.icinga_check(service_desc, "false", e.to_s)
raise e
end
},
lock_not_obtained: lambda {
Services.icinga_check(service_desc, "true", "Unable to lock")
},
)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/tasks/import/local_authorities.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ namespace :import do
namespace :local_authorities do
desc "Import local authority names, codes and tiers from CSV"
task import_all: :environment do
service_desc = "Import local authorities into local-links-manager"
response = LocalLinksManager::Import::LocalAuthoritiesImporter.import_from_csv(File.expand_path("../../../data/local-authorities.csv", File.dirname(__FILE__)))
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::LocalAuthoritiesImporter.import_from_csv(File.expand_path("../../../data/local-authorities.csv", File.dirname(__FILE__)))
end
end
end
29 changes: 6 additions & 23 deletions lib/tasks/import/service_interactions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace :import do
namespace :service_interactions do
desc "Import ServiceInteractions and dependencies"
task import_all: :environment do
service_desc = "Import services and interactions into local-links-manager"
LocalLinksManager::DistributedLock.new("service-imports").lock(
lock_obtained: lambda {
begin
Expand All @@ -20,59 +19,43 @@ namespace :import do
Rake::Task["import:service_interactions:add_service_tiers"].invoke
Rake::Task["import:service_interactions:import_from_publishingapi"].invoke
Rake::Task["import:service_interactions:enable_services"].invoke
# Flag nagios that this servers instance succeeded to stop lingering failures
Services.icinga_check(service_desc, "true", "Success")
rescue StandardError => e
Services.icinga_check(service_desc, "false", e.to_s)
raise e
end
},
lock_not_obtained: lambda {
Services.icinga_check(service_desc, "true", "Unable to lock")
},
)
end

desc "Import Services from standards.esd.org.uk"
task import_services: :environment do
service_desc = "Import services into local-links-manager"
response = LocalLinksManager::Import::ServicesImporter.import
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::ServicesImporter.new.import_records
end

desc "Import Interactions from standards.esd.org.uk"
task import_interactions: :environment do
service_desc = "Import interactions into local-links-manager"
response = LocalLinksManager::Import::InteractionsImporter.import
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::InteractionsImporter.new.import_records
end

desc "Import ServicesInteractions from standards.esd.org.uk"
task import_service_interactions: :environment do
service_desc = "Import service interactions into local-links-manager"
response = LocalLinksManager::Import::ServiceInteractionsImporter.import
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::ServiceInteractionsImporter.new.import_records
end

desc "Add tiers from local_services.csv in publisher to the list of Services imported by `import_services`"
task add_service_tiers: :environment do
service_desc = "Add tiers to services into local-links-manager"
response = LocalLinksManager::Import::ServicesTierImporter.import
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::ServicesTierImporter.new.import_records
end

desc "Enable services used on Gov.uk"
task enable_services: :environment do
service_desc = "Enable services in local-links-manager"
response = LocalLinksManager::Import::EnabledServiceChecker.enable
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::EnabledServiceChecker.enable
end

desc "Import LocalTransactions from Publishing API"
task import_from_publishingapi: :environment do
service_desc = "Import local_transactions to service_interactions from publishing-api"
response = LocalLinksManager::Import::PublishingApiImporter.import
Services.icinga_check(service_desc, response.successful?.to_s, response.message)
LocalLinksManager::Import::PublishingApiImporter.new.import_data
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
end

it "reports a successful import" do
expect(described_class.import).to be_successful
expect(described_class.new.import_data).to be_successful
end

it "imports the local transaction slug and title and enables the service interaction" do
described_class.import
described_class.new.import_data

service_interaction = ServiceInteraction.find_by(service: service0, interaction: interaction0)
expect(service_interaction.govuk_slug).to eq("ring-disposal-services")
Expand All @@ -45,7 +45,7 @@
it "warns of live service interactions not in the import" do
create(:service_interaction, service: service1, interaction: interaction1, live: true)

response = described_class.import
response = described_class.new.import_data

expect(response).to_not be_successful
expect(response.errors).to include(/1 Local Transaction is no longer in the import source/)
Expand All @@ -64,7 +64,7 @@

stub_publishing_api_has_content([duff_local_transaction], "document_type" => "local_transaction", "per_page" => 150)

response = described_class.import
response = described_class.new.import_data

expect(response).to_not be_successful
expect(response.errors).to include(/Found empty LGSL/)
Expand Down

0 comments on commit fefb82e

Please sign in to comment.