ernie 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,10 +23,7 @@ Installation
23
23
 
24
24
  You must have Erlang installed before installing Ernie.
25
25
 
26
- From GitHub:
27
-
28
- gem install mojombo-ernie -s http://gems.github.com \
29
- -s http://gemcutter.org
26
+ $ gem install ernie -s http://gemcutter.org
30
27
 
31
28
 
32
29
  Running
@@ -43,6 +40,7 @@ Running
43
40
  <none> Start an Ernie server.
44
41
  reload-handlers Gracefully reload all of the the ruby handlers
45
42
  and use the new code for all subsequent requests.
43
+ stats Print a list of connection and handler statistics.
46
44
 
47
45
  Examples:
48
46
  ernie -d -p 9999 -n 10 -h calc.rb
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 3
2
+ :patch: 4
3
3
  :major: 0
4
4
  :minor: 3
@@ -9,7 +9,8 @@
9
9
  terminate/2, code_change/3]).
10
10
 
11
11
  -record(state, {lsock = undefined,
12
- pending = queue:new()}).
12
+ pending = queue:new(),
13
+ count = 0}).
13
14
 
14
15
  -record(request, {sock = undefined,
15
16
  info = undefined,
@@ -70,7 +71,9 @@ handle_call(_Request, _From, State) ->
70
71
  handle_cast({process, Sock}, State) ->
71
72
  Request = #request{sock = Sock},
72
73
  State2 = receive_term(Request, State),
73
- {noreply, State2};
74
+ Count = State2#state.count,
75
+ State3 = State2#state{count = Count + 1},
76
+ {noreply, State3};
74
77
  handle_cast({asset_freed}, State) ->
75
78
  case queue:is_empty(State#state.pending) of
76
79
  false ->
@@ -127,11 +130,13 @@ process_admin(Sock, reload_handlers, _Args, State) ->
127
130
  ok = gen_tcp:close(Sock),
128
131
  State;
129
132
  process_admin(Sock, stats, _Args, State) ->
133
+ Count = State#state.count,
134
+ CountString = list_to_binary([<<"connections.total=">>, integer_to_list(Count), <<"\n">>]),
130
135
  IdleWorkers = asset_pool:idle_worker_count(),
131
- IdleWorkersString = list_to_binary([<<"idle workers: ">>, integer_to_list(IdleWorkers), <<"\n">>]),
136
+ IdleWorkersString = list_to_binary([<<"workers.idle=">>, integer_to_list(IdleWorkers), <<"\n">>]),
132
137
  QueueLength = queue:len(State#state.pending),
133
- QueueLengthString = list_to_binary([<<"pending connections: ">>, integer_to_list(QueueLength), <<"\n">>]),
134
- gen_tcp:send(Sock, term_to_binary({reply, list_to_binary([IdleWorkersString, QueueLengthString])})),
138
+ QueueLengthString = list_to_binary([<<"connections.pending=">>, integer_to_list(QueueLength), <<"\n">>]),
139
+ gen_tcp:send(Sock, term_to_binary({reply, list_to_binary([CountString, IdleWorkersString, QueueLengthString])})),
135
140
  ok = gen_tcp:close(Sock),
136
141
  State;
137
142
  process_admin(Sock, _Fun, _Args, State) ->
data/ernie.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ernie}
5
- s.version = "0.3.3"
5
+ s.version = "0.3.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Tom Preston-Werner"]
9
- s.date = %q{2009-08-20}
9
+ s.date = %q{2009-09-06}
10
10
  s.default_executable = %q{ernie}
11
11
  s.email = %q{tom@mojombo.com}
12
12
  s.executables = ["ernie"]
data/examples/calc.rb CHANGED
@@ -1,8 +1,24 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'ernie'
3
3
 
4
+ # Just about the easiest example I could thing of.
4
5
  mod(:calc) do
5
6
  fun(:add) do |a, b|
6
7
  a + b
7
8
  end
9
+ end
10
+
11
+ # Useful for tests that need to simulate longer running functions.
12
+ mod(:slowcalc) do
13
+ fun(:add) do |a, b|
14
+ sleep(rand * 2)
15
+ a + b
16
+ end
17
+ end
18
+
19
+ # Throw an error
20
+ mod(:errorcalc) do
21
+ fun(:add) do |a, b|
22
+ raise "abandon hope!"
23
+ end
8
24
  end
data/lib/ernie.rb CHANGED
@@ -59,6 +59,8 @@ class Ernie
59
59
  def self.dispatch(mod, fun, args)
60
60
  xargs = deconvert(args)
61
61
  self.log("-- " + [mod, fun, xargs].inspect)
62
+ self.mods[mod] || raise(ServerError.new("No such module: '#{mod}'"))
63
+ self.mods[mod].funs[fun] || raise(ServerError.new("No such function '#{mod}:#{fun}'"))
62
64
  res = self.mods[mod].funs[fun].call(*xargs)
63
65
  convert(res)
64
66
  end
@@ -74,8 +76,13 @@ class Ernie
74
76
  xres = [:reply, res]
75
77
  self.log("<- " + xres.inspect)
76
78
  f.send!(xres)
79
+ rescue ServerError => e
80
+ xres = [:error, [:server, 0, e.message, e.backtrace]]
81
+ self.log("<- " + xres.inspect)
82
+ self.log(e.backtrace.join("\n"))
83
+ f.send!(xres)
77
84
  rescue Object => e
78
- xres = [:error, [:user, 0, e.message]]
85
+ xres = [:error, [:user, 0, e.message, e.backtrace]]
79
86
  self.log("<- " + xres.inspect)
80
87
  self.log(e.backtrace.join("\n"))
81
88
  f.send!(xres)
@@ -105,6 +112,8 @@ class Ernie
105
112
  end
106
113
  end
107
114
 
115
+ class Ernie::ServerError < StandardError; end
116
+
108
117
  class Ernie::Mod
109
118
  attr_accessor :name, :funs
110
119
 
data/test/load.rb CHANGED
@@ -1,14 +1,18 @@
1
1
  require 'bertrpc'
2
2
 
3
+ $stdout.sync = true
4
+
3
5
  threads = []
4
6
  svc = BERTRPC::Service.new('localhost', 8000)
5
7
 
6
- 5.times do
8
+ 8.times do
7
9
  threads << Thread.new do
8
10
  i = 0
9
- 100.times { i += svc.call.calc.add(1, 2) }
10
- print "#{i}\n"
11
+ 10.times { i += svc.call.calc.add(1, 2); print '.'; $stdout.flush }
12
+ print "(#{i})"
11
13
  end
12
14
  end
13
15
 
14
- threads.each { |t| t.join }
16
+ threads.each { |t| t.join }
17
+
18
+ puts
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ernie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-20 00:00:00 -07:00
12
+ date: 2009-09-06 00:00:00 -07:00
13
13
  default_executable: ernie
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency