Class: TurbotRunner::BaseRunner
- Inherits:
-
Object
- Object
- TurbotRunner::BaseRunner
- Defined in:
- lib/turbot_runner.rb
Instance Method Summary collapse
-
#initialize(bot_directory) ⇒ BaseRunner
constructor
A new instance of BaseRunner.
- #interrupt ⇒ Object
- #run(opts = {}) ⇒ Object
Constructor Details
#initialize(bot_directory) ⇒ BaseRunner
Returns a new instance of BaseRunner.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/turbot_runner.rb', line 7 def initialize(bot_directory) @bot_directory = bot_directory manifest_path = File.join(bot_directory, 'manifest.json') raise "Could not find #{manifest_path}" unless File.exist?(manifest_path) begin @config = JSON.parse(open(manifest_path) {|f| f.read}) rescue JSON::ParserError # TODO provide better error message raise "Could not parse #{manifest_path} as JSON" end @interrupted = false @schemas = {} end |
Instance Method Details
#interrupt ⇒ Object
70 71 72 |
# File 'lib/turbot_runner.rb', line 70 def interrupt @interrupted = true end |
#run(opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/turbot_runner.rb', line 24 def run(opts={}) validation_required = opts[:validate] || true command = "#{interpreter_for(scraper_file)} #{scraper_file}" data_type = @config['data_type'] begin run_script_each_line(command) do |line| record = JSON.parse(line) errors = validate(record, data_type) if errors.empty? handle_valid_record(record, data_type) transformers.each do |transformer| file = File.join(@bot_directory, transformer['file']) command1 = "#{interpreter_for(file)} #{file}" data_type1 = transformer['data_type'] run_script_each_line(command1, :input => line) do |line1| record1 = JSON.parse(line1) errors = validate(record1, data_type1) if errors.empty? handle_valid_record(record1, data_type1) else handle_invalid_record(record1, data_type1, errors) end end end else handle_invalid_record(record, data_type, errors) end end if @interrupted handle_interrupted_run else handle_successful_run end rescue ScriptError => e handle_failed_run end end |