whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Add more info methods
Date Wed, 23 Sep 2020 14:54:10 GMT
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 278e2ab  Add more info methods
278e2ab is described below

commit 278e2ab53917faeeed6183b98f9ae971136907e7
Author: Sebb <sebb@apache.org>
AuthorDate: Wed Sep 23 15:54:00 2020 +0100

    Add more info methods
---
 lib/whimsy/asf/active.rb | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/whimsy/asf/active.rb b/lib/whimsy/asf/active.rb
index b487bf9..106e189 100644
--- a/lib/whimsy/asf/active.rb
+++ b/lib/whimsy/asf/active.rb
@@ -19,13 +19,36 @@ module Whimsy
 
   # this hostname
   def self.hostname
-    `hostname` # TODO: could be cached?
+    `hostname`.chomp # TODO: could be cached?
   end
 
+  # are we migrating?
+  def self.migrating?
+    false # Edit as needed
+  end
+
+  # are we a test node?
+  def self.testnode?
+    # Assume test nodes are not called whimsy...[.apache.org]
+    hostname !~ %r{^whimsy.*(\.apache\.org)?$}
+  end
+
+  # If local updates are not allowed, return reason string, else nil
+  # nil if:
+  # - active node
+  # - not migrating
+  # - or testnode
+  def self.updates_disallowed_reason
+    return nil if testnode?
+    return 'Service temporarily unavailable due to migration.' if migrating?
+    return 'Service unavailable on this node. Please ensure you have logged in to the correct
host.' unless active?
+
+    nil
+  end
 end
 
 # for debugging purposes
 if __FILE__ == $0
-  puts Whimsy.active?
-  puts Whimsy.hostname
-end
\ No newline at end of file
+  puts "active?: #{Whimsy.active?} hostname: #{Whimsy.hostname} migrating?: #{Whimsy.migrating?}"
+  puts "reason: #{Whimsy.updates_disallowed_reason}"
+end


Mime
View raw message