lib/rflow.rb in rflow-1.0.1 vs lib/rflow.rb in rflow-1.1.0
- old
+ new
@@ -1,7 +1,7 @@
-require "rubygems"
-require "bundler/setup"
+require 'rubygems'
+require 'bundler/setup'
require 'time'
require 'active_record'
require 'eventmachine'
require 'sqlite3'
require 'rflow/configuration'
@@ -36,11 +36,11 @@
private
def self.establish_configuration
@configuration = Configuration.new(@config_database_path)
unless configuration['rflow.application_directory_path']
- raise ArgumentError, "Empty configuration database! Use a view/controller (such as the RubyDSL) to create a configuration"
+ raise ArgumentError, 'Empty configuration database! Use a view/controller (such as the RubyDSL) to create a configuration'
end
end
def self.chdir_application_directory
# First change to the config db directory, which might hold
@@ -57,7 +57,28 @@
def self.start_master_node
RFlow.logger.info "#{configuration['rflow.application_name']} starting"
@master = Master.new(configuration)
master.daemonize! if @daemonize
master.run! # blocks until EventMachine stops
+ end
+
+ # This ought to be in EM, but we'll put it here instead of monkey-patching
+ def self.next_tick_and_wait
+ mutex = Mutex.new
+ condition = ConditionVariable.new
+
+ mutex.synchronize do # while locked...
+ EM.next_tick do # schedule a job that will...
+ mutex.synchronize do # grab the lock
+ begin
+ yield # do its thing...
+ condition.signal # then wake us up when it's done...
+ rescue
+ condition.signal # even if the thing fails
+ raise
+ end
+ end
+ end
+ condition.wait(mutex) # drop the mutex to allow the job to run
+ end
end
end