added sleep delay flag

This commit is contained in:
oleghasjanov 2024-09-26 15:18:45 +03:00
parent 44958c79bb
commit 468e9e829f
2 changed files with 11 additions and 6 deletions

View file

@ -256,5 +256,3 @@ allow_accr_endspoints: 'true'
whitelist_companies: whitelist_companies:
- '12345678' - '12345678'
- '87654321' - '87654321'
business_registry_sleep_time: 4

View file

@ -7,7 +7,7 @@ require 'optparse'
require 'rake_option_parser_boilerplate' require 'rake_option_parser_boilerplate'
namespace :company_status do namespace :company_status do
# bundle exec rake company_status:check_all -- --open_data_file_path=tmp/ettevotja_rekvisiidid__lihtandmed.csv --missing_companies_output_path=tmp/missing_companies_in_business_registry.csv --deleted_companies_output_path=tmp/deleted_companies_from_business_registry.csv --download_path=https://avaandmed.ariregister.rik.ee/sites/default/files/avaandmed/ettevotja_rekvisiidid__lihtandmed.csv.zip --soft_delete_enable=false --registrants_only=true # bundle exec rake company_status:check_all -- --open_data_file_path=tmp/ettevotja_rekvisiidid__lihtandmed.csv --missing_companies_output_path=tmp/missing_companies_in_business_registry.csv --deleted_companies_output_path=tmp/deleted_companies_from_business_registry.csv --download_path=https://avaandmed.ariregister.rik.ee/sites/default/files/avaandmed/ettevotja_rekvisiidid__lihtandmed.csv.zip --soft_delete_enable=false --sleep_time=4 --registrants_only=true
desc 'Get Estonian companies status from Business Registry.' desc 'Get Estonian companies status from Business Registry.'
DELETED_FROM_REGISTRY_STATUS = 'K' DELETED_FROM_REGISTRY_STATUS = 'K'
@ -25,6 +25,7 @@ namespace :company_status do
soft_delete_enable = options[:soft_delete_enable] soft_delete_enable = options[:soft_delete_enable]
downloaded_filename = File.basename(URI(download_path).path) downloaded_filename = File.basename(URI(download_path).path)
are_registrants_only = options[:registrants_only] are_registrants_only = options[:registrants_only]
sleep_time = options[:sleep_time]
puts "*** Run 1 step. Downloading fresh open data file. ***" puts "*** Run 1 step. Downloading fresh open data file. ***"
remove_old_file(DESTINATION + downloaded_filename) remove_old_file(DESTINATION + downloaded_filename)
@ -58,7 +59,8 @@ namespace :company_status do
contact: contact, contact: contact,
missing_companies_in_business_registry_path: missing_companies_in_business_registry_path, missing_companies_in_business_registry_path: missing_companies_in_business_registry_path,
deleted_companies_from_business_registry_path: deleted_companies_from_business_registry_path, deleted_companies_from_business_registry_path: deleted_companies_from_business_registry_path,
soft_delete_enable: soft_delete_enable soft_delete_enable: soft_delete_enable,
sleep_time: sleep_time
) )
end end
end end
@ -81,6 +83,7 @@ namespace :company_status do
download_path: url, download_path: url,
soft_delete_enable: false, soft_delete_enable: false,
registrants_only: false, registrants_only: false,
sleep_time: 2,
} }
banner = 'Usage: rake companies:check_all -- [options]' banner = 'Usage: rake companies:check_all -- [options]'
@ -97,6 +100,7 @@ namespace :company_status do
download_path: ['-d [DOWNLOAD_PATH]', '--download_path [DOWNLOAD_PATH]', String], download_path: ['-d [DOWNLOAD_PATH]', '--download_path [DOWNLOAD_PATH]', String],
soft_delete_enable: ['-e [SOFT_DELETE_ENABLE]', '--soft_delete_enable [SOFT_DELETE_ENABLE]', FalseClass], soft_delete_enable: ['-e [SOFT_DELETE_ENABLE]', '--soft_delete_enable [SOFT_DELETE_ENABLE]', FalseClass],
registrants_only: ['-r', '--registrants_only [REGISTRANTS_ONLY]', FalseClass], registrants_only: ['-r', '--registrants_only [REGISTRANTS_ONLY]', FalseClass],
sleep_time: ['-s', '--sleep_time [SLEEP_TIME]', Integer],
} }
end end
@ -152,8 +156,11 @@ namespace :company_status do
write_to_csv_file(csv_file_path: path, headers: ["ID", "Ident", "Name", "Contact Type"], attrs: [contact.id, contact.ident, contact.name, determine_contact_type(contact)]) write_to_csv_file(csv_file_path: path, headers: ["ID", "Ident", "Name", "Contact Type"], attrs: [contact.id, contact.ident, contact.name, determine_contact_type(contact)])
end end
def sort_companies_to_files(contact:, missing_companies_in_business_registry_path:, deleted_companies_from_business_registry_path:, soft_delete_enable:) def sort_companies_to_files(contact:, missing_companies_in_business_registry_path:, deleted_companies_from_business_registry_path:, soft_delete_enable:, sleep_time:)
sleep ENV['business_registry_sleep_time'].present? ? ENV['business_registry_sleep_time'].to_i : 2 sleep sleep_time
puts "Sleeping for #{sleep_time} seconds"
resp = contact.return_company_details resp = contact.return_company_details
if resp.empty? if resp.empty?