lib/picky/interfaces/live_parameters.rb in picky-1.5.2 vs lib/picky/interfaces/live_parameters.rb in picky-1.5.3
- old
+ new
@@ -7,16 +7,16 @@
# while the Application is running.
#
# Important Note: This will only work in Master/Child configurations.
#
class LiveParameters
-
+
def initialize
@child, @parent = IO.pipe
start_master_process_thread
end
-
+
# This runs a thread that listens to child processes.
#
def start_master_process_thread
# This thread is stopped in the children.
#
@@ -28,22 +28,23 @@
next unless Hash === configuration_hash
next if configuration_hash.empty?
exclaim "Trying to update MASTER configuration."
try_updating_configuration_with configuration_hash
kill_each_worker_except pid
- # TODO rescue on error.
-
+
+ # Fails hard on an error.
+ #
end
end
end
-
+
# TODO This needs to be webserver agnostic.
#
def worker_pids
Unicorn::HttpServer::WORKERS.keys
end
-
+
# Taken from Unicorn.
#
def kill_each_worker_except pid
worker_pids.each do |wpid|
next if wpid == pid
@@ -59,18 +60,18 @@
# TODO This needs to be Webserver agnostic.
#
def remove_worker wpid
worker = Unicorn::HttpServer::WORKERS.delete(wpid) and worker.tmp.close rescue nil
end
-
+
# Updates any parameters with the ones given and
# returns the updated params.
#
# The params are a strictly defined hash of:
# * querying_removes_characters: Regexp
# * querying_stopwords: Regexp
- # TODO etc.
+ # * querying_splits_text_on: Regexp
#
# This first tries to update in the child process,
# and if successful, in the parent process
#
def parameters configuration_hash
@@ -101,21 +102,21 @@
# Close the child if it isn't yet closed.
#
def close_child
@child.close unless @child.closed?
end
-
+
class CouldNotUpdateConfigurationError < StandardError
attr_reader :config_key
def initialize config_key, message
super message
@config_key = config_key
end
end
-
+
# Tries updating the configuration in the child process or parent process.
- #
+ #
def try_updating_configuration_with configuration_hash
current_key = nil
begin
configuration_hash.each_pair do |key, new_value|
exclaim " Setting #{key} with #{new_value}."
@@ -126,19 +127,19 @@
# Catch any error and reraise as config error.
#
raise CouldNotUpdateConfigurationError.new current_key, e.message
end
end
-
+
def extract_configuration
{
querying_removes_characters: querying_removes_characters,
querying_stopwords: querying_stopwords,
querying_splits_text_on: querying_splits_text_on
}
end
-
+
# TODO Move to Interface object.
#
def querying_removes_characters
Tokenizers::Query.default.instance_variable_get(:@removes_characters_regexp).source
end
@@ -155,13 +156,19 @@
Tokenizers::Query.default.instance_variable_get(:@splits_text_on_regexp).source
end
def querying_splits_text_on= new_value
Tokenizers::Query.default.instance_variable_set(:@splits_text_on_regexp, %r{#{new_value}})
end
-
+
+ #
+ #
+ def to_s
+ "Suckerfish Live Interface (Use the picky-live gem to introspect)"
+ end
+
end
-
+
# Aka.
#
::LiveParameters = LiveParameters
-
+
end
\ No newline at end of file