quartz 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebfd7d4019c4952c5fa8c089d1e40c7bd99d3383
4
- data.tar.gz: 7383e1077dc7f67d1040b7249c84cf7504da6c41
3
+ metadata.gz: e8f6c9a4a2b1be439b263d6e8edcf851a7dff9bc
4
+ data.tar.gz: 6c289fdd3023c9c331352779eef346c2c7259371
5
5
  SHA512:
6
- metadata.gz: 6d2874247cf7b5f25156452ccdb81c9a3d0a749fdeb125498e628f911edbf6c0c14fc1f24108579056b5bb3202011e2376d864dc7b31ebfd33b3fb23639e5641
7
- data.tar.gz: 28c083a54b0191ece7ab3e735de9b41aa8d459535a8ca2bc2ef7db01ad19036fa0d6d2509ed7bb0969f189460bb594db5d9127099472ece45a25c18f6e1f0667
6
+ metadata.gz: 7ab102e4110877642bb02c149548f2e8746e258797ab85f2637d9ebc439fb8f634a451e686607d3dc7633ae20d6344045ae3c6669d1048cd4a71204df363043e
7
+ data.tar.gz: f923a2061e727caecb1e8a3bd12b17e5003cc6c7404c1ff4a552d773795a45bfa9eda42b6704dff052a441315d3fa33ae79d4f086d4ec710ce2ac1616d8db6bb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.6
2
+ - [#13] Meaningful exception types
3
+ - [#20] Speed up Go Quartz process boot time
4
+ - [#22] Handle large buffers
5
+
1
6
  # 0.2.5
2
7
  - [#12] Make seeds in Go process wrappers threadsafe
3
8
  - Destroy socket files upon exit inside Go processes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -0,0 +1,7 @@
1
+ module Quartz
2
+ class ArgumentError < StandardError; end
3
+ class ConfigError < StandardError; end
4
+ class GoResponseError < StandardError; end
5
+ class GoServerError < StandardError; end
6
+ class ResponseError < StandardError; end
7
+ end
@@ -16,7 +16,7 @@ class Quartz::GoProcess
16
16
  elsif opts[:bin_path]
17
17
  @go_process = IO.popen(opts[:bin_path])
18
18
  else
19
- raise 'Missing go binary'
19
+ raise Quartz::ConfigError, 'Missing go binary'
20
20
  end
21
21
 
22
22
  block_until_server_starts
@@ -27,7 +27,7 @@ class Quartz::GoProcess
27
27
  @temp_file_path = "/tmp/quartz_runner_#{seed}"
28
28
 
29
29
  unless system('go', 'build', '-o', @temp_file_path, path)
30
- raise 'Go compilation failed'
30
+ raise Quartz::ConfigError, 'Go compilation failed'
31
31
  end
32
32
 
33
33
  @go_process = IO.popen(@temp_file_path)
@@ -42,14 +42,14 @@ class Quartz::GoProcess
42
42
  end
43
43
 
44
44
  def block_until_server_starts
45
- max_retries = 10
45
+ max_retries = 20
46
46
  retries = 0
47
- delay = 0.1 # seconds
47
+ delay = 0.001 # seconds
48
48
 
49
49
  loop do
50
- raise 'RPC server not starting' if retries > max_retries
51
50
  return if File.exists?(@socket_path)
52
- sleep(delay * retries * 2**retries)
51
+ raise Quartz::GoServerError, 'RPC server not starting' if retries > max_retries
52
+ sleep(delay * 2**retries)
53
53
  retries += 1
54
54
  end
55
55
  end
@@ -67,7 +67,7 @@ class Quartz::GoProcess
67
67
  response = read
68
68
 
69
69
  if response['error']
70
- raise "Metadata error: #{read['error']}"
70
+ raise Quartz::GoResponseError, "Metadata error: #{read['error']}"
71
71
  end
72
72
 
73
73
  response['result']
@@ -83,10 +83,26 @@ class Quartz::GoProcess
83
83
  read
84
84
  end
85
85
 
86
- MAX_MESSAGE_SIZE = 1_000_000_000 # Bytes
86
+ if ['1.9.3', '2.0.0'].include?(RUBY_VERSION)
87
+ READ_EXCEPTION = IO::WaitReadable
88
+ else
89
+ READ_EXCEPTION = IO::EAGAINWaitReadable
90
+ end
91
+
92
+ MAX_MESSAGE_SIZE = 8192 # Bytes
87
93
 
88
94
  def read
89
- JSON(socket.recv(MAX_MESSAGE_SIZE))
95
+ value = ''
96
+ loop do
97
+ begin
98
+ value << socket.recv_nonblock(MAX_MESSAGE_SIZE)
99
+ break if value.end_with?("\n")
100
+ rescue READ_EXCEPTION
101
+ IO.select([socket], [], [])
102
+ end
103
+ end
104
+
105
+ JSON(value)
90
106
  end
91
107
 
92
108
  def cleanup
@@ -16,7 +16,7 @@ class Quartz::GoStruct
16
16
 
17
17
  def call(method_name, args)
18
18
  unless @struct_methods.include?(method_name)
19
- raise "Invalid method: #{method_name}"
19
+ raise Quartz::ArgumentError, "Invalid method: #{method_name}"
20
20
  end
21
21
 
22
22
  arg_info = @method_name_to_arg_info[method_name]
@@ -24,7 +24,7 @@ class Quartz::GoStruct
24
24
  # Validate arguments
25
25
  args.each do |k, v|
26
26
  unless arg_info.include?(k)
27
- raise "Invalid argument: #{k}"
27
+ raise Quartz::ArgumentError, "Invalid argument: #{k}"
28
28
  end
29
29
 
30
30
  # TODO: validate types
@@ -7,7 +7,7 @@ module Quartz::Validations
7
7
  File.exist?(File.join(directory, 'go'))
8
8
  end
9
9
 
10
- raise 'Go not installed.' unless go_exists
10
+ raise Quartz::ConfigError, 'Go not installed.' unless go_exists
11
11
  end
12
12
 
13
13
  def self.check_go_quartz_version
@@ -18,7 +18,7 @@ module Quartz::Validations
18
18
  end[0]
19
19
 
20
20
  unless installed_quartz_dir
21
- raise "GOPATH not configured."
21
+ raise Quartz::ConfigError, "GOPATH not configured."
22
22
  end
23
23
 
24
24
  installed_quartz = File.read(File.join(installed_quartz_dir,
data/lib/quartz.rb CHANGED
@@ -3,9 +3,9 @@ require 'securerandom'
3
3
  require 'socket'
4
4
 
5
5
  module Quartz
6
- class ResponseError < StandardError; end
7
6
  end
8
7
 
8
+ require 'quartz/exceptions'
9
9
  require 'quartz/go_process'
10
10
  require 'quartz/go_struct'
11
11
  require 'quartz/client'
data/quartz.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: quartz 0.2.5 ruby lib
5
+ # stub: quartz 0.2.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "quartz"
9
- s.version = "0.2.5"
9
+ s.version = "0.2.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["David Huie"]
14
- s.date = "2015-02-02"
14
+ s.date = "2015-02-28"
15
15
  s.description = "A gem for calling Go code from Ruby"
16
16
  s.email = "dahuie@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -39,11 +39,14 @@ Gem::Specification.new do |s|
39
39
  "go/quartz/util.go",
40
40
  "lib/quartz.rb",
41
41
  "lib/quartz/client.rb",
42
+ "lib/quartz/exceptions.rb",
42
43
  "lib/quartz/go_process.rb",
43
44
  "lib/quartz/go_struct.rb",
44
45
  "lib/quartz/validations.rb",
45
46
  "quartz.gemspec",
46
47
  "spec/client_spec.rb",
48
+ "spec/examples/long_json.go",
49
+ "spec/examples_spec.rb",
47
50
  "spec/go_process_spec.rb",
48
51
  "spec/go_struct_spec.rb",
49
52
  "spec/spec_helper.rb",
@@ -0,0 +1,28 @@
1
+ package main
2
+
3
+ import "github.com/DavidHuie/quartz/go/quartz"
4
+
5
+ type Example struct{}
6
+
7
+ type ExampleArgs struct {
8
+ Num int
9
+ }
10
+
11
+ type Response struct {
12
+ Output []string
13
+ }
14
+
15
+ func (t *Example) LongJson(args ExampleArgs, response *Response) error {
16
+ result := []string{}
17
+ for i := 0; i < 8192; i++ {
18
+ result = append(result, "Test")
19
+ }
20
+ *response = Response{result}
21
+ return nil
22
+ }
23
+
24
+ func main() {
25
+ example := &Example{}
26
+ quartz.RegisterName("example", example)
27
+ quartz.Start()
28
+ }
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'examples' do
4
+
5
+ describe 'json' do
6
+ it 'should handle long strings of json' do
7
+ client = Quartz::Client.new(file_path: 'spec/examples/long_json.go')
8
+ res = client[:example].call('LongJson', {})['Output']
9
+ expect(res.count).to eq(8192)
10
+ expect(res.first).to eq("Test")
11
+ end
12
+
13
+ it 'should handle many calls' do
14
+ results = []
15
+ client = Quartz::Client.new(file_path: 'spec/examples/long_json.go')
16
+
17
+ 100.times do
18
+ results.concat(client[:example].call('LongJson', {})['Output'])
19
+ end
20
+
21
+ expect(results.count).to eq(819_200)
22
+ end
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quartz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Huie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler
@@ -94,11 +94,14 @@ files:
94
94
  - go/quartz/util.go
95
95
  - lib/quartz.rb
96
96
  - lib/quartz/client.rb
97
+ - lib/quartz/exceptions.rb
97
98
  - lib/quartz/go_process.rb
98
99
  - lib/quartz/go_struct.rb
99
100
  - lib/quartz/validations.rb
100
101
  - quartz.gemspec
101
102
  - spec/client_spec.rb
103
+ - spec/examples/long_json.go
104
+ - spec/examples_spec.rb
102
105
  - spec/go_process_spec.rb
103
106
  - spec/go_struct_spec.rb
104
107
  - spec/spec_helper.rb