@@ -37,7 +37,7 @@ class Client
3737 include Chef ::Mixin ::GenerateURL
3838 include Chef ::Mixin ::Checksum
3939
40- attr_accessor :node , :registration , :json_attribs , :validation_token , :node_name , :ohai , :rest
40+ attr_accessor :node , :registration , :json_attribs , :validation_token , :node_name , :ohai , :rest , :runner
4141
4242 # Creates a new Chef::Client.
4343 def initialize ( )
@@ -47,6 +47,7 @@ def initialize()
4747 @json_attribs = nil
4848 @node_name = nil
4949 @node_exists = true
50+ @runner = nil
5051 @ohai = Ohai ::System . new
5152 Chef ::Log . verbose = Chef ::Config [ :verbose_logging ]
5253 Mixlib ::Authentication ::Log . logger = Ohai ::Log . logger = Chef ::Log . logger
@@ -77,21 +78,32 @@ def initialize()
7778 # === Returns
7879 # true:: Always returns true.
7980 def run
80- start_time = Time . now
81- Chef ::Log . info ( "Starting Chef Run" )
82-
83- determine_node_name
84- register
85- build_node ( @node_name )
86- save_node
87- sync_cookbooks
88- save_node
89- converge
90- save_node
91-
92- end_time = Time . now
93- Chef ::Log . info ( "Chef Run complete in #{ end_time - start_time } seconds" )
94- true
81+ begin
82+ start_time = Time . now
83+ Chef ::Log . info ( "Starting Chef Run" )
84+
85+ determine_node_name
86+ register
87+ build_node ( @node_name )
88+ save_node
89+ sync_cookbooks
90+ save_node
91+ converge
92+ save_node
93+
94+ end_time = Time . now
95+ total_time = end_time - start_time
96+ Chef ::Log . info ( "Chef Run complete in #{ total_time } seconds" )
97+ Chef ::Config [ :report_handlers ] . each do |handler |
98+ handler . report ( @node , @runner , total_time )
99+ end
100+ true
101+ rescue Exception => e
102+ Chef ::Config [ :exception_handlers ] . each do |handler |
103+ handler . exception ( @node , @runner , e )
104+ end
105+ raise
106+ end
95107 end
96108
97109 # Similar to Chef::Client#run, but instead of talking to the Chef server,
@@ -316,7 +328,8 @@ def converge(solo=false)
316328 compile = Chef ::Compile . new ( @node )
317329
318330 Chef ::Log . debug ( "Converging node #{ @node_name } " )
319- Chef ::Runner . new ( @node , compile . collection , compile . definitions , compile . cookbook_loader ) . converge
331+ @runner = Chef ::Runner . new ( @node , compile . collection , compile . definitions , compile . cookbook_loader )
332+ @runner . converge
320333 true
321334 end
322335
0 commit comments