(whimsy) branch master updated: Oops, needs to be in module

2024-01-09 Thread sebb
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 861a38dd Oops, needs to be in module
861a38dd is described below

commit 861a38dda9faca5e8e852a86f773f9bfade7e458
Author: Sebb 
AuthorDate: Tue Jan 9 23:44:11 2024 +

Oops, needs to be in module
---
 lib/whimsy/asf/status.rb | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/lib/whimsy/asf/status.rb b/lib/whimsy/asf/status.rb
index c70cc5a1..50c2e9e7 100644
--- a/lib/whimsy/asf/status.rb
+++ b/lib/whimsy/asf/status.rb
@@ -57,21 +57,22 @@ module Status
 
 nil
   end
-end
 
-def self.currentIP # intended for CLI testing
-  Resolv::DNS.open do |rs|
-begin
-  @currentIP ||= rs.getaddress(hostname) # local as IP; should not change 
during a run
-rescue Resolv::ResolvError => e # allow this to fail on a test node
-  raise unless testnode?
-  $stderr.puts "WARNING: Failed to resolve local IP address: #{e}"
+  def self.currentIP # intended for CLI testing
+Resolv::DNS.open do |rs|
+  begin
+@currentIP ||= rs.getaddress(hostname) # local as IP; should not 
change during a run
+  rescue Resolv::ResolvError => e # allow this to fail on a test node
+raise unless testnode?
+$stderr.puts "WARNING: Failed to resolve local IP address: #{e}"
+  end
 end
   end
-end
-
-def self.activeIP # intended for CLI testing
-  Resolv::DNS.open.getaddress(ACTIVE_HOSTNAME)
+  
+  def self.activeIP # intended for CLI testing
+Resolv::DNS.open.getaddress(ACTIVE_HOSTNAME)
+  end
+  
 end
 
 # for debugging purposes



(whimsy) branch master updated: Rework: cache where possible; use marker file for migrating status

2024-01-09 Thread sebb
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 48ebc952 Rework: cache where possible; use marker file for migrating 
status
48ebc952 is described below

commit 48ebc9527d40e5d2fd28b72c20e42198f272341a
Author: Sebb 
AuthorDate: Tue Jan 9 23:40:21 2024 +

Rework: cache where possible; use marker file for migrating status
---
 .gitignore   |  1 +
 lib/whimsy/asf/status.rb | 48 
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index 11bf4474..59742496 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ work
 .rakeTasks
 /assets/
 maintenance.txt
+migrating.txt
 .ruby-version
diff --git a/lib/whimsy/asf/status.rb b/lib/whimsy/asf/status.rb
index 58877489..c70cc5a1 100644
--- a/lib/whimsy/asf/status.rb
+++ b/lib/whimsy/asf/status.rb
@@ -7,24 +7,36 @@ require 'resolv'
 
 # common methods
 module Status
+  ACTIVE_HOSTNAME = "whimsy.apache.org"
+
+  # Cache unchanging values
+  @currentIP = nil # may not be resolvable
+  @hostname = nil
 
   # Are we the active node?
+  # i.e. is our IP address the same as that of the active node
   def self.active?
 Resolv::DNS.open do |rs|
-  active = rs.getaddress("whimsy.apache.org") # Official hostname as IP
-  current = rs.getaddress(Socket.gethostname) rescue nil # local as IP
-  return current == active
+  active = rs.getaddress(ACTIVE_HOSTNAME) # Official hostname as IP; might 
change during run
+  begin
+@currentIP ||= rs.getaddress(hostname) # local as IP; should not 
change during a run
+  rescue Resolv::ResolvError => e # allow this to fail on a test node
+raise unless testnode?
+$stderr.puts "WARNING: Failed to resolve local IP address: #{e}"
+  end
+  return @currentIP == active
 end
   end
 
   # this hostname
   def self.hostname
-`hostname`.chomp # TODO: could be cached?
+@hostname ||= Socket.gethostname
+@hostname
   end
 
   # are we migrating?
-  def self.migrating?
-false # Edit as needed
+  def self.migrating? # This is used to disable updates, see 
self.updates_disallowed_reason
+File.exist? '/srv/whimsy/migrating.txt' # default is false
   end
 
   # are we a test node?
@@ -47,8 +59,28 @@ module Status
   end
 end
 
+def self.currentIP # intended for CLI testing
+  Resolv::DNS.open do |rs|
+begin
+  @currentIP ||= rs.getaddress(hostname) # local as IP; should not change 
during a run
+rescue Resolv::ResolvError => e # allow this to fail on a test node
+  raise unless testnode?
+  $stderr.puts "WARNING: Failed to resolve local IP address: #{e}"
+end
+  end
+end
+
+def self.activeIP # intended for CLI testing
+  Resolv::DNS.open.getaddress(ACTIVE_HOSTNAME)
+end
+
 # for debugging purposes
 if __FILE__ == $0
-  puts "active?: #{Status.active?} hostname: #{Status.hostname} migrating?: 
#{Status.migrating?}"
-  puts "reason: #{Status.updates_disallowed_reason}"
+  puts "hostname: #{Status.hostname}"
+  puts "IP: #{Status.currentIP || 'nil'}"
+  puts "Active IP: #{Status.activeIP} for #{Status::ACTIVE_HOSTNAME}"
+  puts "active?: #{Status.active?}"
+  puts "migrating?: #{Status.migrating?}"
+  puts "testnode?: #{Status.testnode?}"
+  puts "updates disallowed reason: #{Status.updates_disallowed_reason}"
 end