daemon-kit 0.1.8.1 → 0.1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -4
- data/Gemfile +4 -0
- data/History.txt +8 -0
- data/README.rdoc +3 -3
- data/Rakefile +3 -25
- data/Upgrading.md +21 -0
- data/bin/daemon-kit +1 -1
- data/daemon-kit.gemspec +36 -256
- data/lib/daemon_kit.rb +2 -2
- data/lib/daemon_kit/arguments.rb +3 -3
- data/lib/daemon_kit/commands/console.rb +1 -1
- data/lib/daemon_kit/deployment/capistrano.rb +7 -39
- data/lib/daemon_kit/dk_amqp.rb +1 -1
- data/lib/daemon_kit/initializer.rb +14 -37
- data/lib/daemon_kit/ruote_participants.rb +9 -2
- data/lib/daemon_kit/ruote_workitem.rb +6 -6
- data/lib/daemon_kit/version.rb +6 -0
- data/lib/generators/daemon_kit/amqp/templates/config/pre-daemonize/amqp.rb +0 -1
- data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +1 -1
- data/lib/generators/daemon_kit/app/templates/Gemfile +5 -0
- data/lib/generators/daemon_kit/app/templates/config/boot.rb +2 -8
- data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +0 -4
- data/lib/generators/daemon_kit/app/templates/config/pre-daemonize/safely.rb +13 -0
- data/lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt +5 -4
- data/lib/generators/daemon_kit/ruote/templates/config/pre-daemonize/ruote.rb +0 -1
- data/spec/initializer_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -3
- data/tasks/rspec.rake +5 -6
- metadata +123 -49
- data/lib/daemon_kit/error_handlers/base.rb +0 -32
- data/lib/daemon_kit/error_handlers/hoptoad.rb +0 -180
- data/lib/daemon_kit/safety.rb +0 -84
- data/spec/error_handlers_spec.rb +0 -23
data/lib/daemon_kit/safety.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module DaemonKit
|
2
|
-
# Provides a wrapper for running code inside a 'safety net' Any
|
3
|
-
# exceptions raised inside a safety net is handled and reported via
|
4
|
-
# loggers, email or Hoptoad.
|
5
|
-
#
|
6
|
-
# The safety net can be configured via DaemonKit.config.safety,
|
7
|
-
# which holds the only instance of the safety net.
|
8
|
-
class Safety
|
9
|
-
|
10
|
-
# Who get's notified.
|
11
|
-
@handler = nil
|
12
|
-
attr_accessor :handler
|
13
|
-
|
14
|
-
# Registered error handlers
|
15
|
-
@error_handlers = {}
|
16
|
-
attr_reader :error_handlers
|
17
|
-
|
18
|
-
class << self
|
19
|
-
|
20
|
-
# Singleton
|
21
|
-
@instance = nil
|
22
|
-
|
23
|
-
def instance
|
24
|
-
@instance ||= new
|
25
|
-
end
|
26
|
-
private :new
|
27
|
-
|
28
|
-
# Run the provided block inside a safety net.
|
29
|
-
def run(&block)
|
30
|
-
self.instance.run(&block)
|
31
|
-
end
|
32
|
-
|
33
|
-
def register_error_handler( klass )
|
34
|
-
name = klass.to_s.split('::').last.downcase
|
35
|
-
|
36
|
-
DaemonKit.logger.debug( "Registering error handler '#{name}' (#{klass})" ) if DaemonKit.logger
|
37
|
-
|
38
|
-
instance.instance_eval( <<-EOF, __FILE__, __LINE__ )
|
39
|
-
def #{name}
|
40
|
-
@#{name} ||= #{klass}.instance
|
41
|
-
end
|
42
|
-
EOF
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Run the provided block inside a safety net.
|
47
|
-
def run(&block)
|
48
|
-
begin
|
49
|
-
block.call
|
50
|
-
rescue => e
|
51
|
-
# Log
|
52
|
-
DaemonKit.logger.fatal "Safety net caught exception: #{e.message}"
|
53
|
-
DaemonKit.logger.fatal "Backtrace: #{e.backtrace.join("\n ")}"
|
54
|
-
|
55
|
-
get_handler.handle_exception( e ) if get_handler
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def get_handler
|
60
|
-
if @handler && self.respond_to?( @handler )
|
61
|
-
h = send( @handler )
|
62
|
-
return h if h.class.ancestors.include?( DaemonKit::ErrorHandlers::Base )
|
63
|
-
end
|
64
|
-
|
65
|
-
return nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class Object
|
71
|
-
class << self
|
72
|
-
def safely(&block)
|
73
|
-
DaemonKit::Safety.run(&block)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def safely(&block)
|
78
|
-
DaemonKit::Safety.run(&block)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Load our error handlers
|
83
|
-
require 'daemon_kit/error_handlers/base'
|
84
|
-
require 'daemon_kit/error_handlers/hoptoad'
|
data/spec/error_handlers_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe DaemonKit::Safety do
|
4
|
-
end
|
5
|
-
|
6
|
-
describe DaemonKit::ErrorHandlers::Mail do
|
7
|
-
it "should send an email report" do
|
8
|
-
conf = Object.new
|
9
|
-
conf.stubs(:daemon_name).returns('test')
|
10
|
-
DaemonKit.stubs(:configuration).returns(conf)
|
11
|
-
|
12
|
-
fake_smtp = Object.new
|
13
|
-
fake_smtp.expects(:start).with('localhost.localdomain', nil, nil, nil)
|
14
|
-
Net::SMTP.expects(:new).with('localhost', 25).returns(fake_smtp)
|
15
|
-
|
16
|
-
begin
|
17
|
-
raise RuntimeError, "specs don't fail :)"
|
18
|
-
rescue => e
|
19
|
-
handler = DaemonKit::ErrorHandlers::Mail.instance
|
20
|
-
handler.handle_exception( e )
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|