whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: move from IPC to Listen
Date Wed, 09 Nov 2016 21:05:18 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  9df1211   move from IPC to Listen
9df1211 is described below

commit 9df12112c6b94603cdf70691ac4521ca7258e5fa
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Wed Nov 9 16:04:54 2016 -0500

    move from IPC to Listen
---
 www/board/agenda/bin/remind-cronjob.rb          |  1 -
 www/board/agenda/daemon/channel.rb              | 47 +++++++++++++++++++++++++
 www/board/agenda/main.rb                        |  1 -
 www/board/agenda/models/agenda.rb               | 19 ----------
 www/board/agenda/models/ipc.rb                  | 47 -------------------------
 www/board/agenda/models/pending.rb              | 28 ---------------
 www/board/agenda/routes.rb                      | 11 +++++-
 www/board/agenda/views/actions/draft.json.rb    |  2 --
 www/board/agenda/views/actions/feedback.json.rb |  1 -
 www/board/agenda/views/actions/minute.json.rb   |  2 --
 www/board/agenda/views/actions/todos.json.rb    |  1 -
 www/board/agenda/views/layout/main.js.rb        |  1 -
 12 files changed, 57 insertions(+), 104 deletions(-)

diff --git a/www/board/agenda/bin/remind-cronjob.rb b/www/board/agenda/bin/remind-cronjob.rb
index 95e83f0..5e440ad 100644
--- a/www/board/agenda/bin/remind-cronjob.rb
+++ b/www/board/agenda/bin/remind-cronjob.rb
@@ -18,7 +18,6 @@ FOUNDATION_BOARD = ASF::SVN['private/foundation/board']
 AGENDA_WORK = ASF::Config.get(:agenda_work).untaint || '/srv/agenda'
 
 require './models/agenda'
-require './models/ipc'
 
 # draft reminder text
 @reminder = ARGV.first || 'reminder1'
diff --git a/www/board/agenda/daemon/channel.rb b/www/board/agenda/daemon/channel.rb
index df34f5f..0ae2096 100644
--- a/www/board/agenda/daemon/channel.rb
+++ b/www/board/agenda/daemon/channel.rb
@@ -5,13 +5,19 @@
 
 require 'json'
 require 'concurrent'
+require 'listen'
+require 'digest'
+require 'yaml'
 
 require_relative './session'
+require 'whimsy/asf/svn'
 
 class Channel
   @@sockets = Concurrent::Map.new
   @@users = Concurrent::Map.new {|map,key| map[key]=[]}
 
+  FOUNDATION_BOARD = ASF::SVN['private/foundation/board']
+
   # add a new socket/userid pair
   def self.add(ws, id)
     @@users[id] << ws
@@ -41,6 +47,7 @@ class Channel
 
   # send a message to a specific user
   def self.post_private(user, msg)
+    msg = JSON.dump(msg) if msg.instance_of? Hash
     self.post @@users[user] || [], msg
   end
 
@@ -78,4 +85,44 @@ class Channel
       client.close
     end
   end
+
+  # listen for changes to agenda files
+  board_listener = Listen.to(FOUNDATION_BOARD) do |modified, added, removed|
+    STDERR.puts [modified, added, removed].inspect
+    modified.each do |path|
+      next unless File.exist?(path)
+      file = File.basename(path)
+      if file =~ /^board_agenda_[\d_]+.txt$/
+        contents = File.read(path)
+        digest = Digest::SHA256.base64digest(contents)
+        self.post_all type: :agenda, file: file, digest: digest
+      end
+    end
+  end
+
+  board_listener.start
+ # listen for changes to pending and minutes files
+  work_listener = Listen.to(Session::AGENDA_WORK) do |modified, added, removed|
+    modified.each do |path|
+      next if path.end_with? '/sessions/present.yml'
+      next unless File.exist?(path)
+      file = File.basename(path)
+      if path =~ /board_agenda_\d+_\d+_\d+.txt$/
+        contents = File.read(path)
+        digest = Digest::SHA256.base64digest(contents)
+        self.post_all type: :agenda, file: file, digest: digest
+      elsif file =~ /^board_minutes_\d{4}_\d\d_\d\d\.yml$/
+        agenda = file.sub('minutes', 'agenda').sub('.yml', '.txt')
+        self.post_all type: :minutes, agenda: agenda, 
+          value: YAML.load_file(path)
+      elsif file =~ /^(\w+)\.yml$/
+        self.post_private $1, type: :pending, private: $1,
+          value: YAML.load_file(path)
+      else
+        STDERR.puts file
+      end
+    end
+  end
+
+  work_listener.start
 end
diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index 018a914..022bca9 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -33,7 +33,6 @@ end
 FileUtils.mkdir_p AGENDA_WORK if not Dir.exist? AGENDA_WORK
 
 require_relative './routes'
-require_relative './models/ipc'
 require_relative './models/pending'
 require_relative './models/agenda'
 require_relative './models/minutes'
diff --git a/www/board/agenda/models/agenda.rb b/www/board/agenda/models/agenda.rb
index b4a6acd..fc8bc00 100755
--- a/www/board/agenda/models/agenda.rb
+++ b/www/board/agenda/models/agenda.rb
@@ -65,7 +65,6 @@ class Agenda
       current[:mtime].to_i <= 0
     then
       Agenda[file] = update
-      IPC.post type: :agenda, file: file, digest: update[:digest] unless quick
     end
   end
 
@@ -154,7 +153,6 @@ class Agenda
         if output != input
           IO.write(path, output)
           commit_rc = _.system ['svn', 'commit', auth, path, '-m', message]
-          @@seen[path] = File.mtime(path)
         end
       else
         output = IO.read(path)
@@ -191,21 +189,4 @@ class Agenda
   ensure
     FileUtils.rm_rf dir
   end
-
-  # listen for changes to agenda files
-  @@listener = Listen.to(FOUNDATION_BOARD) do |modified, added, removed|
-    modified.each do |path|
-      next if File.exist?(path) and @@seen[path] == File.mtime(path)
-      file = File.basename(path)
-      if file =~ /^board_agenda_[\d_]+.txt$/
-        self.update_cache(file, path, File.read(path), false)
-      end
-    end
-  end
-
-  # disable listening when running tests
-  @@listener = Struct.new(:start, :stop).new if ENV['RACK_ENV'] == 'test'
-
-  @@seen = {}
-  @@listener.start
 end
diff --git a/www/board/agenda/models/ipc.rb b/www/board/agenda/models/ipc.rb
deleted file mode 100644
index 64e5e0f..0000000
--- a/www/board/agenda/models/ipc.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require 'yaml'
-
-module IPC
-
-  if Dir.exist? '/etc/letsencrypt'
-    @@url ="wss://127.0.0.1:34234"
-  else
-    @@url ="ws://127.0.0.1:34234"
-  end
-
-  def self.post(data)
-    thread = Thread.new do
-      # post to web socket server
-      ws = WebSocket::Client::Simple.connect @@url
-
-      begin
-        done = false
-        ws.on :open do
-          if data[:private]
-            headers = "private: #{data[:private]}\n\n"
-          else
-            headers = ''
-          end
-
-          ws.send headers + JSON.dump(data)
-          done = true
-        end
-
-        sleep 0.1 until done
-      ensure
-        ws.close
-      end
-    end
-  end
-
-  @@present = []
-  @@mtime = nil
-  def self.present
-    file = File.join(AGENDA_WORK, 'sessions', 'present.yml')
-    if not File.exist?(file) or File.mtime(file) == @@mtime
-      @@present
-    else
-      @@mtime = File.mtime(file)
-      @@present = YAML.load_file(file)
-    end
-  end
-end
diff --git a/www/board/agenda/models/pending.rb b/www/board/agenda/models/pending.rb
index bb5b98c..067083d 100644
--- a/www/board/agenda/models/pending.rb
+++ b/www/board/agenda/models/pending.rb
@@ -36,35 +36,7 @@ class Pending
     File.open(work, 'w') do |file|
       file.write YAML.dump(pending)
     end
-    @@seen[work] = File.mtime(work)
-
-    IPC.post type: :pending, value: pending, private: user
 
     pending
   end
-
-  # listen for changes to pending and minutes files
-  @@listener = Listen.to(AGENDA_WORK) do |modified, added, removed|
-    modified.each do |path|
-      next if path.end_with? '/sessions/present.yml'
-      next if path =~ /board_agenda_\d+_\d+_\d+.txt$/
-      next if File.exist?(path) and @@seen[path] == File.mtime(path)
-      file = File.basename(path)
-      if file =~ /^board_minutes_\d{4}_\d\d_\d\d\.yml$/
-        agenda = file.sub('minutes', 'agenda').sub('.yml', '.txt')
-        IPC.post type: :minutes, agenda: agenda, value: YAML.load_file(path)
-      elsif file =~ /^(\w+)\.yml$/
-        IPC.post type: :pending, private: $1, value: YAML.load_file(path)
-      else
-        STDERR.puts file
-      end
-    end
-  end
-
-  # disable listening when running tests
-  @@listener = Struct.new(:start, :stop).new if ENV['RACK_ENV'] == 'test'
-
-  @@seen = {}
-
-  @@listener.start
 end
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index b84795e..709ad17 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -89,6 +89,15 @@ get %r{/(\d\d\d\d-\d\d-\d\d)/(.*)} do |date, path|
     role = :guest
   end
 
+  # determine who is present
+  @present = []
+  @present_mtime = nil
+  file = File.join(AGENDA_WORK, 'sessions', 'present.yml')
+  if File.exist?(file) and File.mtime(file) != @present_mtime
+    @present_mtime = File.mtime(file)
+    @present = YAML.load_file(file)
+  end
+
   @server = {
     userid: userid,
     agendas: dir('board_agenda_*.txt').sort,
@@ -97,7 +106,7 @@ get %r{/(\d\d\d\d-\d\d-\d\d)/(.*)} do |date, path|
     username: username,
     firstname: username.split(' ').first.downcase,
     initials: initials,
-    online: IPC.present,
+    online: @present,
     session: Session.user(userid),
     role: role,
     directors: Hash[ASF::Service['board'].members.map {|person| 
diff --git a/www/board/agenda/views/actions/draft.json.rb b/www/board/agenda/views/actions/draft.json.rb
index e720939..5b6e1a6 100644
--- a/www/board/agenda/views/actions/draft.json.rb
+++ b/www/board/agenda/views/actions/draft.json.rb
@@ -25,6 +25,4 @@ end
 
 drafts = Dir.chdir(FOUNDATION_BOARD) {Dir['board_minutes_*.txt'].sort}
 
-IPC.post type: :server, drafts: drafts
-
 drafts
diff --git a/www/board/agenda/views/actions/feedback.json.rb b/www/board/agenda/views/actions/feedback.json.rb
index d434ad8..e1296b0 100644
--- a/www/board/agenda/views/actions/feedback.json.rb
+++ b/www/board/agenda/views/actions/feedback.json.rb
@@ -102,7 +102,6 @@ unless @dryrun
   minutes[:todos][:feedback_sent] ||= []
   minutes[:todos][:feedback_sent] += output.map {|item| item[:title]}
   File.write minutes_file, YAML.dump(minutes)
-  IPC.post type: :minutes, agenda: @agenda, value: minutes
 end
 
 # return output to client
diff --git a/www/board/agenda/views/actions/minute.json.rb b/www/board/agenda/views/actions/minute.json.rb
index 85f4386..23f27b6 100644
--- a/www/board/agenda/views/actions/minute.json.rb
+++ b/www/board/agenda/views/actions/minute.json.rb
@@ -112,6 +112,4 @@ end
 
 File.write minutes_file, YAML.dump(minutes)
 
-IPC.post type: :minutes, agenda: @agenda, value: minutes
-
 minutes
diff --git a/www/board/agenda/views/actions/todos.json.rb b/www/board/agenda/views/actions/todos.json.rb
index 9221638..e7e3ce4 100644
--- a/www/board/agenda/views/actions/todos.json.rb
+++ b/www/board/agenda/views/actions/todos.json.rb
@@ -131,7 +131,6 @@ end
 
 unless todos == minutes[:todos]
   File.write minutes_file, YAML.dump(minutes)
-  IPC.post type: :minutes, agenda: @agenda, value: minutes
 end
 
 ########################################################################
diff --git a/www/board/agenda/views/layout/main.js.rb b/www/board/agenda/views/layout/main.js.rb
index 70f6385..607895f 100644
--- a/www/board/agenda/views/layout/main.js.rb
+++ b/www/board/agenda/views/layout/main.js.rb
@@ -153,7 +153,6 @@ class Main < React
     Agenda.fetch(@@page.etag, @@page.digest)
 
     # start Service Worker
-    console.log 'starting'
     PageCache.register() if PageCache.enabled
   
     # start backchannel

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message