spider-gazelle 0.1.3 → 0.1.4

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: ddf67f2f83bb093e412603cfaccbdff9465fd492
4
- data.tar.gz: 418b883c22f28aec01358f7e1583b5102eed3452
3
+ metadata.gz: a635e54f6ee2156e7a387e7e84c9934b28591b2d
4
+ data.tar.gz: c93b073acb5665495ccede21a2a817e87fc57328
5
5
  SHA512:
6
- metadata.gz: 8e6bf5475f273760fb5bcbcd0e73988a292d3f473d95e96a6b043168b303b46403fac5e4c2b1201693ef2b51cdd3b250b1ef593c43ba2407e2e006443101556c
7
- data.tar.gz: 5c62a4b4dd5a142b2a0f8090cac2ff67a2004305bf9c0ca78d2c4c8cb4e7043115d8b9b338180d76ab249af439838fce58ea093bac83dbc26d3936fec5c77659
6
+ metadata.gz: 54f76fcb8ec1e75541371a4e373031f5d0a127048581e0cecf74c22205c31e562a9865278369a122f017e9a692ee58913f322b9bb27c20947cf2b4c5a62ab916
7
+ data.tar.gz: 39999c854db582de74be926631a5bff1ad2e6cda7354425622bdba6eef3cddd47eb8cd1bcb6d74b415b87a90b248d8a42425be5ed68a9f6bbc9e908c585a48e8
data/bin/sg CHANGED
@@ -6,25 +6,24 @@ require 'optparse'
6
6
 
7
7
 
8
8
  options = {
9
- host: "0.0.0.0",
10
- port: 3000,
11
- tls: false,
9
+ Host: "0.0.0.0",
10
+ Port: 3000,
12
11
  environment: ENV['RACK_ENV'] || 'development',
13
12
  rackup: "#{Dir.pwd}/config.ru",
14
- quiet: false
13
+ Verbose: false
15
14
  }
16
15
 
17
16
  parser = OptionParser.new do |opts|
18
17
  opts.on "-p", "--port PORT", Integer, "Define what port TCP port to bind to (default: 3000)" do |arg|
19
- options[:port] = arg
18
+ options[:Port] = arg
20
19
  end
21
20
 
22
21
  opts.on "-a", "--address HOST", "bind to HOST address (default: 0.0.0.0)" do |arg|
23
- options[:host] = arg
22
+ options[:Host] = arg
24
23
  end
25
24
 
26
- opts.on "-q", "--quiet", "quiet down the output" do
27
- options[:quiet] = true
25
+ opts.on "-v", "--verbose", "loud output" do
26
+ options[:Verbose] = true
28
27
  end
29
28
 
30
29
  opts.on "-e", "--environment ENVIRONMENT", "The environment to run the Rack app on (default: development)" do |arg|
@@ -36,7 +35,7 @@ parser = OptionParser.new do |opts|
36
35
  end
37
36
 
38
37
  opts.on "-l", "--logfile FILE", "Location of the servers log file (default: logs/server.log)" do |arg|
39
- options[:rackup] = arg
38
+ ENV['SG_LOG'] = arg
40
39
  end
41
40
 
42
41
  opts.on "-m", "--mode MODE", "Either thread, process or no_ipc (default: thread)" do |arg|
@@ -60,7 +59,6 @@ unless File.exists?(options[:rackup])
60
59
  abort "No rackup found at #{options[:rackup]}"
61
60
  end
62
61
 
63
- ENV['RACK_ENV'] = options[:environment].to_s
64
62
  # Force process mode on Windows (pipes + sockets not working at the moment)
65
63
  ENV['SG_MODE'] = 'no_ipc' if ::FFI::Platform.windows?
66
64
 
@@ -4,13 +4,6 @@ require 'set'
4
4
 
5
5
  module SpiderGazelle
6
6
  class Binding
7
- DEFAULT_OPTIONS = {
8
- :Host => '0.0.0.0',
9
- :Port => 3000,
10
- :tls => false,
11
- :optimize_for_latency => true,
12
- :backlog => 1024
13
- }
14
7
 
15
8
 
16
9
  attr_reader :app_id
@@ -18,7 +11,7 @@ module SpiderGazelle
18
11
 
19
12
  def initialize(loop, delegate, app_id, options = {})
20
13
  @app_id = app_id
21
- @options = DEFAULT_OPTIONS.merge(options)
14
+ @options = options
22
15
  @loop = loop
23
16
  @delegate = delegate
24
17
  @port = @options[:Port]
@@ -2,7 +2,8 @@ require 'set'
2
2
  require 'thread'
3
3
  require 'logger'
4
4
  require 'singleton'
5
- require 'fileutils'
5
+ require 'fileutils' # mkdir_p
6
+ require 'forwardable' # run method
6
7
 
7
8
 
8
9
  module SpiderGazelle
@@ -20,11 +21,47 @@ module SpiderGazelle
20
21
  DEFAULT_OPTIONS = {
21
22
  :Host => '0.0.0.0',
22
23
  :Port => 8080,
23
- :Verbose => false
24
+ :Verbose => false,
25
+ :tls => false,
26
+ :optimize_for_latency => true,
27
+ :backlog => 1024
24
28
  }
25
29
 
30
+ def self.run(app, options = {})
31
+ options = DEFAULT_OPTIONS.merge(options)
32
+
33
+ ENV['RACK_ENV'] = options[:environment].to_s if options[:environment]
34
+
35
+ puts "Look out! Here comes Spider-Gazelle #{::SpiderGazelle::VERSION}!"
36
+ puts "* Environment: #{ENV['RACK_ENV']} on #{RUBY_ENGINE || 'ruby'} #{RUBY_VERSION}"
37
+
38
+ server = instance
39
+ server.run do |logger|
40
+ logger.progress server.method(:log)
41
+ server.loaded.then do
42
+ puts "* Loading: #{app}"
43
+
44
+ # yield server if block_given?
45
+
46
+ server.load(app, options).catch(proc {|e|
47
+ puts "#{e.message}\n#{e.backtrace.join("\n") unless e.backtrace.nil?}\n"
48
+ }).finally do
49
+ # This will execute if the TCP binding is lost
50
+ # Terminating the application
51
+ Process.kill 'INT', 0
52
+ end
53
+
54
+ puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"
55
+ end
56
+ end
57
+ end
58
+
59
+
26
60
  attr_reader :state, :mode, :threads, :logger
27
61
 
62
+ extend Forwardable
63
+ def_delegators :@web, :run
64
+
28
65
 
29
66
  def initialize
30
67
  # Threaded mode by default
@@ -71,42 +108,6 @@ module SpiderGazelle
71
108
  end
72
109
  end
73
110
 
74
- def run(&block)
75
- @web.run &block
76
- end
77
-
78
- def self.run(app, options = {})
79
- options = DEFAULT_OPTIONS.merge(options)
80
-
81
- instance.run do |logger|
82
- logger.progress do |level, errorid, error|
83
- begin
84
- puts "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
85
- rescue Exception
86
- p 'error in gazelle logger'
87
- end
88
- end
89
-
90
- puts "Look out! Here comes Spider-Gazelle #{::SpiderGazelle::VERSION}!"
91
- puts "* Environment: #{ENV['RACK_ENV']} on #{RUBY_ENGINE || 'ruby'} #{RUBY_VERSION}"
92
- server = ::SpiderGazelle::Spider.instance
93
- server.loaded.then do
94
- puts "* Loading: #{app}"
95
-
96
- # yield server if block_given?
97
-
98
- server.load(app, options).catch(proc {|e|
99
- puts "#{e.message}\n#{e.backtrace.join("\n") unless e.backtrace.nil?}\n"
100
- }).finally do
101
- # This will execute if the TCP binding is lost
102
- server.shutdown
103
- end
104
-
105
- puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"
106
- end
107
- end
108
- end
109
-
110
111
  # Provides a promise that resolves when we are read to start binding applications
111
112
  #
112
113
  # @return [::Libuv::Q::Promise] that indicates when the gazelles are loaded
@@ -1,3 +1,3 @@
1
1
  module SpiderGazelle
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spider-gazelle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach