turbot-runner 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/prerun.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Disable output buffering
2
+ STDOUT.sync = true
3
+ STDERR.sync = true
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/turbot_runner.rb CHANGED
@@ -4,6 +4,9 @@ module TurbotRunner
4
4
  class ScriptError < StandardError; end
5
5
 
6
6
  class BaseRunner
7
+
8
+ attr_reader :wait_thread
9
+
7
10
  def initialize(bot_directory)
8
11
  @bot_directory = bot_directory
9
12
 
@@ -26,12 +29,10 @@ module TurbotRunner
26
29
 
27
30
  command = "#{interpreter_for(scraper_file)} #{scraper_file}"
28
31
  data_type = @config['data_type']
29
-
30
32
  begin
31
33
  run_script_each_line(command) do |line|
32
34
  record = JSON.parse(line)
33
35
  errors = validate(record, data_type)
34
-
35
36
  if errors.empty?
36
37
  handle_valid_record(record, data_type)
37
38
 
@@ -63,7 +64,11 @@ module TurbotRunner
63
64
  handle_successful_run
64
65
  end
65
66
  rescue ScriptError => e
66
- handle_failed_run
67
+ if @interrupted
68
+ handle_interrupted_run
69
+ else
70
+ handle_failed_run
71
+ end
67
72
  end
68
73
  end
69
74
 
@@ -119,6 +124,7 @@ module TurbotRunner
119
124
  def run_script_each_line(command, options={})
120
125
  # TODO: handle timeouts, errors
121
126
  Open3::popen2(command) do |stdin, stdout, wait_thread|
127
+ @wait_thread = wait_thread
122
128
  if options[:input]
123
129
  stdin.puts(options[:input])
124
130
  stdin.close
@@ -156,7 +162,8 @@ module TurbotRunner
156
162
  def interpreter_for(file)
157
163
  case file
158
164
  when /\.rb$/
159
- 'ruby'
165
+ prerun = File.expand_path("../prerun.rb", __FILE__)
166
+ "ruby -r#{prerun}"
160
167
  when /\.py$/
161
168
  'python'
162
169
  else
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - OpenCorporates
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
12
+ date: 2014-07-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json-schema
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - '='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
@@ -31,8 +34,13 @@ extensions: []
31
34
  extra_rdoc_files: []
32
35
  files:
33
36
  - bin/rspec
37
+ - lib/prerun.rb
34
38
  - lib/turbot_runner.rb
35
39
  - lib/turbot_runner/version.rb
40
+ - spec/dummy-bot/manifest.json
41
+ - spec/dummy-bot/scraper.rb
42
+ - spec/dummy-bot/transformer.rb
43
+ - spec/turbot_runner_spec.rb
36
44
  - schema/schemas/company-schema.json
37
45
  - schema/schemas/includes/address.json
38
46
  - schema/schemas/includes/base-statement.json
@@ -50,33 +58,29 @@ files:
50
58
  - schema/schemas/share-parcel-schema.json
51
59
  - schema/schemas/simple-licence-schema.json
52
60
  - schema/schemas/subsidiary-relationship-schema.json
53
- - spec/dummy-bot/manifest.json
54
- - spec/dummy-bot/scraper.rb
55
- - spec/dummy-bot/transformer.rb
56
- - spec/turbot_runner_spec.rb
57
61
  homepage: http://turbot.opencorporates.com/
58
62
  licenses:
59
63
  - MIT
60
- metadata: {}
61
64
  post_install_message:
62
65
  rdoc_options: []
63
66
  require_paths:
64
67
  - lib
65
68
  required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
66
70
  requirements:
67
71
  - - ! '>='
68
72
  - !ruby/object:Gem::Version
69
73
  version: 1.9.2
70
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
71
76
  requirements:
72
77
  - - ! '>='
73
78
  - !ruby/object:Gem::Version
74
79
  version: '0'
75
80
  requirements: []
76
81
  rubyforge_project:
77
- rubygems_version: 2.2.2
82
+ rubygems_version: 1.8.23
78
83
  signing_key:
79
- specification_version: 4
84
+ specification_version: 3
80
85
  summary: Utilities for running bots with Turbot
81
86
  test_files: []
82
- has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2YxNWRlNmYwMTk4YjNmNzU5MmEyMGVjNGUzMTQ5ZTg3Y2NmNTllNg==
5
- data.tar.gz: !binary |-
6
- MjM2YTE3N2E2MTM1MmEzNmY1NmY0MWU1NDIxYzFhMDkxMzZiYmM4Ng==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- OGFlZjRmMjUwMzY0ZmJkNjk2M2ExZmQ3ZmVmMjFmMmI3Y2Y0MmVhNjFkNThh
10
- MjExOTMyZDI3MmI4YWZlM2NlYTQzYjZjZDI0Nzg1OTI1MjllNWJiMzBlMzBl
11
- YzU2NmU3ZDUxZDliNDAyOTY1ZGQxMDhhYTU1OWQ4NWQwNjkzMTE=
12
- data.tar.gz: !binary |-
13
- MzRkYWNkMzIwZWNlNGQzNDExYzVmMmU4NjNmYTMwNGRlZmNhN2MyZTJjODQ4
14
- MWY0Yzc2Njc0YWZlODViZjUzNjBlOWRjNmE1OTg1MGFiMjI2OWE5Y2JkODYy
15
- OTY5NTE1YjBjNjhlOWFkNmJjM2Y0MTIzMjdjNmMzYmZjMDQwZGU=