robustserver 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/robustserver.rb +26 -12
  3. metadata +122 -39
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/robustserver.rb CHANGED
@@ -104,19 +104,21 @@ end
104
104
  # Subclasses should implements *#run*, which will be your main-worker.
105
105
  # For initializing, you can override **#initialize**, but doen't forget to call **super**.
106
106
  class RobustServer
107
- attr_reader :signals
107
+ class UnimplementedRun <Exception
108
+ end
109
+ attr_reader :signals, :output
108
110
 
109
111
  def self.main *argv
110
112
  self.new( *argv).main
111
113
  end
112
114
 
113
- def initialize *p
115
+ def initialize *_
114
116
  sh = method :signal_handler
115
117
  @sigs = {
116
118
  Signal[:INT] => sh, Signal[:HUP] => nil, Signal[:TERM] => sh,
117
119
  Signal[:KILL] => sh, Signal[:USR1] => nil, Signal[:USR2] => nil
118
120
  }
119
- @signals = []
121
+ @signals, @output = [], $stderr
120
122
  end
121
123
 
122
124
  def trapping
@@ -124,28 +126,40 @@ class RobustServer
124
126
  end
125
127
 
126
128
  def signal_handler s
127
- $stderr.puts [:signal, s, Signal[s]].inspect
128
- s = s
129
+ output.puts [:signal, s, Signal[s]].inspect
129
130
  @signals.push s unless @signals.include? s
130
131
  end
131
132
 
132
133
  def main max = nil, range = nil
133
134
  retries = Retries.new max, range
134
135
  trapping
135
- $stderr.puts "Arbeit wird nun aufgenommen..."
136
+ output.puts "Running...."
136
137
  begin
137
138
  self.run
138
- rescue SystemExit, Interrupt, SignalException
139
- $stderr.puts "Das Beenden des Programms wurde angefordert. #{$!}"
139
+ rescue UnimplementedRun
140
+ output.puts $!.message
141
+ exit 1
142
+ rescue SystemExit
143
+ output.puts "Server interrupted by signal: #$!"
144
+ raise
145
+ rescue Interrupt, SignalException
146
+ output.puts "Server interrupted by signal: #$!"
147
+ exit 0
140
148
  rescue Object
141
- $stderr.puts [:rescue, $!, $!.class, $!.backtrace].inspect
149
+ output.puts [:rescue, $!, $!.class, $!.backtrace].inspect
142
150
  retry if retries.retry?
143
- $stderr.print "Zuviele Fehler in zu kurzer Zeit. Ich gebe auf und "
151
+ output.print "Too many errors in too short time. Give up: "
152
+ exit 2
144
153
  end
145
- $stderr.puts "Unbeachtete Signale: #{@signals.map(&Signal.method(:[])).join( ', ')}"
154
+ ensure
155
+ output.puts "Disregarded signals: #{@signals.map(&Signal.method(:[])).join( ', ')}" unless @signals.empty?
146
156
  trapping
147
157
  self.at_exit
148
- $stderr.puts "Beende mich selbst."
158
+ output.puts "Shutdown."
159
+ end
160
+
161
+ def run
162
+ raise UnimplementedRun, "Unimplemented #{self.class.name}#run."
149
163
  end
150
164
 
151
165
  def at_exit
metadata CHANGED
@@ -1,67 +1,150 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: robustserver
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Denis Knauf
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-03-21 00:00:00 +01:00
18
- default_executable:
19
- dependencies: []
20
-
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
21
110
  description: Protects your Server against SIGS and rescues all exceptions.
22
111
  email: Denis.Knauf@gmail.com
23
112
  executables: []
24
-
25
113
  extensions: []
26
-
27
- extra_rdoc_files:
114
+ extra_rdoc_files:
28
115
  - LICENSE
29
116
  - README.md
30
- files:
117
+ files:
31
118
  - AUTHORS
32
119
  - README.md
33
120
  - VERSION
34
121
  - lib/robustserver.rb
35
122
  - LICENSE
36
- has_rdoc: true
37
123
  homepage: http://github.com/DenisKnauf/robustserver
38
124
  licenses: []
39
-
40
125
  post_install_message:
41
- rdoc_options:
42
- - --charset=UTF-8
43
- require_paths:
126
+ rdoc_options: []
127
+ require_paths:
44
128
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- segments:
50
- - 0
51
- version: "0"
52
- required_rubygems_version: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- segments:
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ segments:
57
136
  - 0
58
- version: "0"
137
+ hash: -383789649
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
59
144
  requirements: []
60
-
61
145
  rubyforge_project:
62
- rubygems_version: 1.3.6
146
+ rubygems_version: 1.8.23
63
147
  signing_key:
64
148
  specification_version: 3
65
149
  summary: Robust Server
66
150
  test_files: []
67
-