This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 5f51b47b Send mail details of shutdown
5f51b47b is described below

commit 5f51b47b11e9513bd0f0d0a3de435f6fbbaa5b53
Author: Sebb <[email protected]>
AuthorDate: Mon Apr 1 17:10:31 2024 +0100

    Send mail details of shutdown
---
 tools/pubsub-ci-email.rb | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/tools/pubsub-ci-email.rb b/tools/pubsub-ci-email.rb
index 42692eed..77ca742f 100755
--- a/tools/pubsub-ci-email.rb
+++ b/tools/pubsub-ci-email.rb
@@ -16,6 +16,20 @@ def stamp(*s)
   "%s: %s" % [Time.now.gmtime.to_s, s.join(' ')]
 end
 
+def mail_notify(subject, body=nil)
+  mail = Mail.new do
+    to '[email protected]'
+    from '[email protected]'
+    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 @@ class PubSub
     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 @@ class PubSub
         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 @@ class PubSub
     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 @@ if $0 == __FILE__
     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 @@ if $0 == __FILE__
 
   Generated by #{__FILE__}
   EOD
-  mail = Mail.new do
-    to '[email protected]'
-    from '[email protected]'
-    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 = {}

Reply via email to