Class: DataPitcher::Batch
- Inherits:
-
Object
- Object
- DataPitcher::Batch
- Defined in:
- lib/data_pitcher/batch.rb
Instance Method Summary collapse
- #command_hashes ⇒ Object
- #execute(dry_run: true) ⇒ Object
-
#initialize(yaml_path = DataPitcher.configuration.data_pitcher_yaml_path) ⇒ Batch
constructor
A new instance of Batch.
Constructor Details
#initialize(yaml_path = DataPitcher.configuration.data_pitcher_yaml_path) ⇒ Batch
Returns a new instance of Batch.
5 6 7 |
# File 'lib/data_pitcher/batch.rb', line 5 def initialize(yaml_path = DataPitcher.configuration.data_pitcher_yaml_path) @yaml_path = yaml_path end |
Instance Method Details
#command_hashes ⇒ Object
9 10 11 12 |
# File 'lib/data_pitcher/batch.rb', line 9 def command_hashes # TODO: 例外処理 YAML.load(ERB.new(File.read(@yaml_path)).result)['data_pitcher'] end |
#execute(dry_run: true) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/data_pitcher/batch.rb', line 14 def execute(dry_run: true) command_hashes.each.with_index(1) do |command_hash, index| begin result = false elapsed_time = Benchmark.realtime do result = DataPitcher::Command.new( spreadsheet_key: command_hash['spreadsheet_key'], worksheet_title: command_hash['worksheet_title'], sql_path: command_hash['sql_path'], dry_run: dry_run, index: index ).execute end if result puts "##{index} command: sending completed. #{elapsed_time}s" end rescue => e puts "[ERROR] ##{index} command skipped: #{e.class} #{e.}" end end end |