Class: DataPitcher::Batch
- Inherits:
-
Object
- Object
- DataPitcher::Batch
- Defined in:
- lib/data_pitcher/batch.rb
Instance Method Summary collapse
- #commands ⇒ 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
#commands ⇒ Object
9 10 11 12 |
# File 'lib/data_pitcher/batch.rb', line 9 def commands # 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 |
# File 'lib/data_pitcher/batch.rb', line 14 def execute(dry_run: true) commands.each.with_index(1) do |command, index| begin result = false elapsed_time = Benchmark.realtime do result = DataPitcher::Command.new(command['spreadsheet_key'], command['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.message}" end end end |