Send mail details of shutdown
diff --git a/tools/pubsub-ci-email.rb b/tools/pubsub-ci-email.rb
index 42692ee..77ca742 100755
--- a/tools/pubsub-ci-email.rb
+++ b/tools/pubsub-ci-email.rb
@@ -16,6 +16,20 @@
"%s: %s" % [Time.now.gmtime.to_s, s.join(' ')]
end
+def mail_notify(subject, body=nil)
+ mail = Mail.new do
+ to 'notifications@whimsical.apache.org'
+ from 'notifications@whimsical.apache.org'
+ subject subject
+ body body
+ end
+ if Status.active? or Status.testnode?
+ mail.deliver!
+ else
+ puts stamp "Would have sent: #{mail}"
+ end
+end
+
class PubSub
require 'fileutils'
@@ -28,6 +42,7 @@
mtime = File.mtime(__FILE__)
FileUtils.touch(ALIVE) # Temporary debug - ensure exists
done = false
+ except = nil
ps_thread = Thread.new do
begin
uri = URI.parse(url)
@@ -80,9 +95,11 @@
puts stamp "Done with start" if debug
rescue Errno::ECONNREFUSED => e
@restartable = true
+ except = e
puts stamp e.inspect
sleep 3
rescue StandardError => e
+ except = e
puts stamp e.inspect
puts stamp e.backtrace
end
@@ -90,7 +107,12 @@
end # thread
puts stamp "Pubsub thread started #{url} ..."
ps_thread.join
- puts stamp "Pubsub thread finished %s..." % (@updated ? '(code updated) ' : '')
+ subject = "Pubsub thread finished %s..." % (@updated ? '(code updated) ' : '')
+ puts stamp subject
+ mail_notify subject, <<~EOD
+ Restartable: #{@restartable}
+ Exception: #{except.inspect}
+ EOD
if @restartable and ! ARGV.include? '--prompt'
puts stamp 'restarting'
@@ -273,7 +295,7 @@
error = nil
end
- body = <<~EOD
+ mail_notify subject, <<~EOD
This is a test email
Previous revision #{previous_revision}
Current revision #{latest}
@@ -281,14 +303,7 @@
Generated by #{__FILE__}
EOD
- mail = Mail.new do
- to 'notifications@whimsical.apache.org'
- from 'notifications@whimsical.apache.org'
- subject subject
- body body
- end
- mail.deliver! # Does it matter if this is sent from an inactive node?
-
+
raise ArgumentError.new error if error
options = {}