#loop was a bad idea. #run raises UnimplementedRun. on UnimplementedRun main will never retry.
This commit is contained in:
parent
f11b7df104
commit
d7edbb750e
|
@ -104,6 +104,8 @@ end
|
||||||
# Subclasses should implements *#run*, which will be your main-worker.
|
# Subclasses should implements *#run*, which will be your main-worker.
|
||||||
# For initializing, you can override **#initialize**, but doen't forget to call **super**.
|
# For initializing, you can override **#initialize**, but doen't forget to call **super**.
|
||||||
class RobustServer
|
class RobustServer
|
||||||
|
class UnimplementedRun <Exception
|
||||||
|
end
|
||||||
attr_reader :signals, :output
|
attr_reader :signals, :output
|
||||||
|
|
||||||
def self.main *argv
|
def self.main *argv
|
||||||
|
@ -135,6 +137,8 @@ class RobustServer
|
||||||
output.puts "Running...."
|
output.puts "Running...."
|
||||||
begin
|
begin
|
||||||
self.run
|
self.run
|
||||||
|
rescue UnimplementedRun
|
||||||
|
raise
|
||||||
rescue SystemExit
|
rescue SystemExit
|
||||||
output.puts "Server interrupted by signal: #$!"
|
output.puts "Server interrupted by signal: #$!"
|
||||||
raise
|
raise
|
||||||
|
@ -154,11 +158,7 @@ class RobustServer
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
Kernel.loop &method( :loop)
|
raise UnimplementedRun, "Unimplemented #{self.class.name}#run."
|
||||||
end
|
|
||||||
|
|
||||||
def loop
|
|
||||||
raise Exception, "You must implement #{self.class.name}#run or #{self.class.name}#loop."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def at_exit
|
def at_exit
|
||||||
|
|
Loading…
Reference in a new issue