Clean up logs with LoggingHelper
This commit is contained in:
parent
d16680c8ec
commit
21f9b5c6c8
4 changed files with 62 additions and 22 deletions
|
|
@ -36,7 +36,7 @@ module Granblue
|
||||||
should_process = should_download?(download_uri, s3_key)
|
should_process = should_download?(download_uri, s3_key)
|
||||||
return unless should_process
|
return unless should_process
|
||||||
|
|
||||||
log_info "\tDownloading #{size}\t#{url}..."
|
log_info "-> #{size}:\t#{url}..."
|
||||||
|
|
||||||
case @storage
|
case @storage
|
||||||
when :local
|
when :local
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative '../logging_helper'
|
||||||
|
|
||||||
class PostDeploymentManager
|
class PostDeploymentManager
|
||||||
|
include LoggingHelper
|
||||||
|
|
||||||
STORAGE_DESCRIPTIONS = {
|
STORAGE_DESCRIPTIONS = {
|
||||||
local: 'to local disk',
|
local: 'to local disk',
|
||||||
s3: 'to S3',
|
s3: 'to S3',
|
||||||
|
|
@ -26,7 +30,7 @@ class PostDeploymentManager
|
||||||
private
|
private
|
||||||
|
|
||||||
def import_new_data
|
def import_new_data
|
||||||
log_step 'Importing new data...'
|
log_header "Importing new data..."
|
||||||
importer = Granblue::DataImporter.new(
|
importer = Granblue::DataImporter.new(
|
||||||
test_mode: @test_mode,
|
test_mode: @test_mode,
|
||||||
verbose: @verbose
|
verbose: @verbose
|
||||||
|
|
@ -47,18 +51,22 @@ class PostDeploymentManager
|
||||||
end
|
end
|
||||||
|
|
||||||
def rebuild_search_indices
|
def rebuild_search_indices
|
||||||
log_step "\nRebuilding search indices..."
|
log_header 'Rebuilding search indices...'
|
||||||
|
|
||||||
[Character, Summon, Weapon, Job].each do |model|
|
[Character, Summon, Weapon, Job].each do |model|
|
||||||
log_verbose "Rebuilding search index for #{model.name}..."
|
log_verbose "• #{model.name}... "
|
||||||
PgSearch::Multisearch.rebuild(model)
|
PgSearch::Multisearch.rebuild(model)
|
||||||
|
log_verbose "✅ done!\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_import_summary
|
def display_import_summary
|
||||||
log_step "\nImport Summary:"
|
if @new_records.size > 0 || @updated_records.size > 0
|
||||||
display_record_summary("New", @new_records)
|
log_step "\nImport Summary:"
|
||||||
display_record_summary("Updated", @updated_records)
|
display_record_summary("New", @new_records)
|
||||||
|
display_record_summary("Updated", @updated_records)
|
||||||
|
else
|
||||||
|
log_step "\nNo new records imported."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_record_summary(label, records)
|
def display_record_summary(label, records)
|
||||||
|
|
@ -75,7 +83,7 @@ class PostDeploymentManager
|
||||||
if @test_mode
|
if @test_mode
|
||||||
log_step "\nTEST MODE: Would download images for new and updated records..."
|
log_step "\nTEST MODE: Would download images for new and updated records..."
|
||||||
else
|
else
|
||||||
log_step "\nDownloading images for new and updated records..."
|
log_header "Downloading images...", "+"
|
||||||
end
|
end
|
||||||
|
|
||||||
[@new_records, @updated_records].each do |records|
|
[@new_records, @updated_records].each do |records|
|
||||||
|
|
@ -126,12 +134,4 @@ class PostDeploymentManager
|
||||||
def all_records_empty?
|
def all_records_empty?
|
||||||
@new_records.values.all?(&:empty?) && @updated_records.values.all?(&:empty?)
|
@new_records.values.all?(&:empty?) && @updated_records.values.all?(&:empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_step(message)
|
|
||||||
puts message
|
|
||||||
end
|
|
||||||
|
|
||||||
def log_verbose(message)
|
|
||||||
puts message if @verbose
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
25
lib/logging_helper.rb
Normal file
25
lib/logging_helper.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module LoggingHelper
|
||||||
|
def log_step(message)
|
||||||
|
puts message
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_verbose(message)
|
||||||
|
print message if @verbose
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_divider(character = '+', leading_newline = true, trailing_newlines = 1)
|
||||||
|
output = ""
|
||||||
|
output += "\n" if leading_newline
|
||||||
|
output += character * 35
|
||||||
|
output += "\n" * trailing_newlines
|
||||||
|
log_step output
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_header(title, character = '+', leading_newline = true)
|
||||||
|
log_divider(character, leading_newline, 0)
|
||||||
|
log_step title
|
||||||
|
log_divider(character, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,12 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative '../granblue/downloaders/base_downloader'
|
||||||
|
require_relative '../logging_helper'
|
||||||
|
|
||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
desc 'Post-deployment tasks: Import new data and download related images. Options: TEST=true for test mode, VERBOSE=true for verbose output, STORAGE=local|s3|both'
|
desc 'Post-deployment tasks: Import new data and download related images. Options: TEST=true for test mode, VERBOSE=true for verbose output, STORAGE=local|s3|both'
|
||||||
task post_deployment: :environment do
|
task post_deployment: :environment do
|
||||||
require_relative '../granblue/downloaders/base_downloader'
|
include LoggingHelper
|
||||||
|
|
||||||
Dir[Rails.root.join('lib', 'granblue', '**', '*.rb')].each { |file| require file }
|
Dir[Rails.root.join('lib', 'granblue', '**', '*.rb')].each { |file| require file }
|
||||||
|
|
||||||
# Ensure Rails environment is loaded
|
# Ensure Rails environment is loaded
|
||||||
Rails.application.eager_load!
|
Rails.application.eager_load!
|
||||||
|
|
||||||
|
log_header('Starting post-deploy script...', '*', false)
|
||||||
|
print "\n"
|
||||||
|
|
||||||
# Parse and validate storage option
|
# Parse and validate storage option
|
||||||
storage = (ENV['STORAGE'] || 'both').to_sym
|
storage = (ENV['STORAGE'] || 'both').to_sym
|
||||||
unless [:local, :s3, :both].include?(storage)
|
unless [:local, :s3, :both].include?(storage)
|
||||||
|
|
@ -20,15 +29,21 @@ namespace :deploy do
|
||||||
storage: storage
|
storage: storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print "Test mode:\t"
|
||||||
if options[:test_mode]
|
if options[:test_mode]
|
||||||
puts 'Test mode enabled'
|
print "✅ Enabled\n"
|
||||||
|
else
|
||||||
|
print "❌ Disabled\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print "Verbose output:\t"
|
||||||
if options[:verbose]
|
if options[:verbose]
|
||||||
puts 'Verbose output enabled'
|
print "✅ Enabled\n"
|
||||||
|
else
|
||||||
|
print "❌ Disabled\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Storage mode: #{storage}"
|
puts "Storage mode:\t#{storage}"
|
||||||
|
|
||||||
# Execute the task
|
# Execute the task
|
||||||
manager = PostDeploymentManager.new(options)
|
manager = PostDeploymentManager.new(options)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue