-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HOTT-4931 Drop CDS Env Var #1716
base: main
Are you sure you want to change the base?
Changes from 13 commits
82e8782
968a1fb
0742c26
497bae1
76a3715
9212de5
ef78254
0f21b3f
c24b2fb
dafd070
380a5b6
7629b1b
97d0c12
54911ac
b3c6771
f58d0f1
007a649
48202cc
f34ed5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ def import | |
return unless proceed_with_import?(filename) | ||
|
||
handler = XmlProcessor.new(@taric_update.issue_date) | ||
|
||
file = TariffSynchronizer::FileService.file_as_stringio(@taric_update) | ||
XmlParser::Reader.new(file, 'record', handler).parse | ||
post_import(file_path: @taric_update.file_path, filename:) | ||
|
@@ -58,19 +59,23 @@ def taric_failed_log(exception, hash) | |
private | ||
|
||
def proceed_with_import?(filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check always returns true (because use_cds? is false) So the method can go |
||
return true unless TradeTariffBackend.use_cds? | ||
|
||
TariffSynchronizer::TaricUpdate.find(filename: filename[0, 30]).blank? | ||
end | ||
|
||
def post_import(file_path:, filename:) | ||
create_update_entry(file_path:, filename:) if TradeTariffBackend.use_cds? | ||
create_update_entry(file_path:, filename:) | ||
Rails.logger.info "Successfully imported Taric file: #{@taric_update.filename}" | ||
end | ||
|
||
def create_update_entry(file_path:, filename:) | ||
file_size = determine_file_size(file_path) | ||
issue_date = Date.parse(filename.scan(/[0-9]{8}/).last) | ||
# handle a filename that doesn't have a date in the expected format of YYYY-MM-DD | ||
date_match = filename.scan(/[0-9_-]{10}/).last | ||
issue_date = if date_match | ||
Date.parse(date_match) | ||
else | ||
Time.zone.today | ||
end | ||
TariffSynchronizer::TaricUpdate.find_or_create( | ||
filename: filename[0, 30], | ||
issue_date:, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ def download | |
end | ||
|
||
def apply | ||
raise WrongEnvironmentError unless TradeTariffBackend.xi? | ||
|
||
check_tariff_updates_failures | ||
check_sequence | ||
|
||
|
@@ -78,6 +80,8 @@ def apply | |
# | ||
# NOTE: this does not remove records from initial seed | ||
def rollback(rollback_date, keep: false) | ||
raise WrongEnvironmentError unless TradeTariffBackend.xi? | ||
|
||
TradeTariffBackend.with_redis_lock do | ||
date = Date.parse(rollback_date.to_s) | ||
|
||
|
@@ -122,7 +126,7 @@ def rollback(rollback_date, keep: false) | |
end | ||
end | ||
|
||
Rails.logger.info "Rolled back to #{date}. Forced keeping records: #{!!keep}" | ||
Rails.logger.info "Rolled back to #{date}. Forced keeping records: #{!keep.nil?}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks odd? means that |
||
end | ||
rescue Redlock::LockError | ||
Rails.logger.warn("Failed to acquire Redis lock for rollback to #{rollback_date}. Keep records: #{keep}") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes may not be required as Taric Updates and importing is processed in app/lib/tariff_synchronizer/taric_update_downloader.rb. It could be that this code is actually redundant now...