class Naginegi::EmbulkRunner
Public Class Methods
new(db_configs: nil, log_level: 'warn', embulk_run_option: '')
click to toggle source
# File lib/naginegi.rb, line 10 def initialize(db_configs: nil, log_level: 'warn', embulk_run_option: '') @logger = Logger.new(STDOUT) @logger.datetime_format = '%Y-%m-%d %H:%M:%S' @db_configs = db_configs || YAML.load_file('database.yml') @log_level = log_level @embulk_run_option = embulk_run_option end
Public Instance Methods
generate_config(bq_config)
click to toggle source
# File lib/naginegi.rb, line 19 def generate_config(bq_config) Naginegi::EmbulkConfig.new.generate_config(@db_configs, bq_config) end
run(bq_config, target_table_names = [], retry_max = 2)
click to toggle source
# File lib/naginegi.rb, line 23 def run(bq_config, target_table_names = [], retry_max = 2) cmd = 'embulk --version' unless system(cmd) @logger.error('Cannot execute Embulk!!') @logger.error('Cofirm Embulk install and environment') return end error_tables = run_and_retry(bq_config, target_table_names, retry_max, 0) unless error_tables.empty? @logger.error('------------------------------------') @logger.error('[FAILED TABLES]') error_tables.each { |table| @logger.error(table) } @logger.error('------------------------------------') end error_tables.empty? end
Private Instance Methods
run_and_retry(bq_config, target_table_names, retry_max, retry_count)
click to toggle source
# File lib/naginegi.rb, line 44 def run_and_retry(bq_config, target_table_names, retry_max, retry_count) error_tables = Naginegi::Embulk.new(@log_level, @embulk_run_option).run( @db_configs, table_configs, bq_config, target_table_names ) if !error_tables.empty? && retry_count < retry_max @logger.warn('------------------------------------') @logger.warn("retry start -> #{retry_count + 1} time") @logger.warn('------------------------------------') error_tables = run_and_retry(bq_config, error_tables, retry_max, retry_count + 1) end error_tables end
table_configs()
click to toggle source
# File lib/naginegi.rb, line 60 def table_configs @table_configs ||= Naginegi::TableConfig.generate_table_configs end