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: rough in a simple (file based) event system
Date Tue, 12 Jun 2018 00:23:42 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys 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 bfb13a1  rough in a simple (file based) event system
bfb13a1 is described below

commit bfb13a1063f2bfedb6c4942d85e8d06be20b1791
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Mon Jun 11 20:23:10 2018 -0400

    rough in a simple (file based) event system
---
 www/board/agenda/daemon/channel.rb |  9 ++++++-
 www/board/agenda/daemon/events.rb  | 49 ++++++++++++++++++++++++++++++++++++++
 www/board/agenda/main.rb           |  1 +
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/www/board/agenda/daemon/channel.rb b/www/board/agenda/daemon/channel.rb
index 8441897..e507d2c 100644
--- a/www/board/agenda/daemon/channel.rb
+++ b/www/board/agenda/daemon/channel.rb
@@ -10,6 +10,7 @@ require 'digest'
 require 'yaml'
 
 require_relative './session'
+require_relative './events'
 require 'whimsy/asf/svn'
 
 class Channel
@@ -100,7 +101,8 @@ class Channel
   end
 
   board_listener.start
- # listen for changes to pending and minutes files
+
+  # 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'
@@ -117,6 +119,8 @@ class Channel
       elsif file =~ /^(\w+)\.yml$/
         self.post_private $1, type: :pending, private: $1,
           value: YAML.load_file(path)
+      elsif path =~ /^\/events\/\w+$/
+        Events.process()
       else
         STDERR.puts file
       end
@@ -124,4 +128,7 @@ class Channel
   end
 
   work_listener.start
+
+  # process pending messages
+  Events.process()
 end
diff --git a/www/board/agenda/daemon/events.rb b/www/board/agenda/daemon/events.rb
new file mode 100644
index 0000000..1faf85d
--- /dev/null
+++ b/www/board/agenda/daemon/events.rb
@@ -0,0 +1,49 @@
+require 'fileutils'
+require 'json'
+require 'securerandom'
+
+require 'whimsy/asf/config'
+
+#
+# Low-tech, file based event manager.  Each message is stored as a separate
+# file on disk, and is deleted once processed.
+#
+# No direct use of timers, events, or threads are made allowing this
+# service to be used in a variety of contexts (e.g. Sinatra and 
+# EventMachine).
+#
+
+class Events
+  if ENV['RACK_ENV'] == 'test'
+    AGENDA_WORK = File.expand_path('test/work/data').untaint
+  else
+    AGENDA_WORK = ASF::Config.get(:agenda_work).untaint || '/srv/agenda'
+  end
+
+  WORKDIR = File.expand_path('events', AGENDA_WORK)
+
+  # capture a message to be sent
+  def self.post(message)
+    filename = SecureRandom.hex(16)
+    File.write(File.join(WORKDIR, filename), JSON.generate(message))
+  end
+
+  # process pending messages
+  def self.process()
+    Dir[File.join(WORKDIR, '*')].each do |file|
+      begin
+        message = JSON.parse(File.read(file))
+        if message[:private]
+          Channel.post_all(message)
+        else
+          Channel.post_private(message[:private], message)
+        end
+      ensure
+        File.unlink file
+      end
+    end
+  end
+
+  # ensure the working directory exists
+  FileUtils.mkdir_p WORKDIR
+end
diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index bbcf8e6..b991243 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -51,6 +51,7 @@ require_relative './models/comments'
 require_relative './helpers/string'
 require_relative './helpers/integer'
 require_relative './daemon/session'
+require_relative './daemon/events'
 
 require 'websocket-client-simple'
 

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

Mime
View raw message