lib/cloud-crowd.rb in documentcloud-cloud-crowd-0.0.3 vs lib/cloud-crowd.rb in documentcloud-cloud-crowd-0.0.4

- old
+ new

@@ -9,13 +9,10 @@ gem 'json' gem 'rest-client' gem 'right_aws' gem 'sinatra' -# Common CloudCrowd libs: -require 'cloud_crowd/core_ext' - # Autoloading for all the pieces which may or may not be needed: autoload :ActiveRecord, 'activerecord' autoload :Benchmark, 'benchmark' autoload :Daemons, 'daemons' autoload :ERB, 'erb' @@ -32,18 +29,19 @@ # Autoload all the CloudCrowd classes which may not be required. autoload :App, 'cloud_crowd/app' autoload :Action, 'cloud_crowd/action' autoload :AssetStore, 'cloud_crowd/asset_store' autoload :Helpers, 'cloud_crowd/helpers' + autoload :Inflector, 'cloud_crowd/inflector' autoload :Job, 'cloud_crowd/models' autoload :WorkUnit, 'cloud_crowd/models' # Root directory of the CloudCrowd gem. ROOT = File.expand_path(File.dirname(__FILE__) + '/..') # Keep the version in sync with the gemspec. - VERSION = '0.0.3' + VERSION = '0.0.4' # A Job is processing if its WorkUnits in the queue to be handled by workers. PROCESSING = 1 # A Job has succeeded if all of its WorkUnits have finished successfully. @@ -86,26 +84,35 @@ # in a path to +database.yml+. def configure_database(config_path) configuration = YAML.load_file(config_path) ActiveRecord::Base.establish_connection(configuration) end + + # Keep an authenticated (if configured to enable authentication) resource + # for the central server. + def central_server + return @central_server if @central_server + params = [CloudCrowd.config[:central_server]] + params += [CloudCrowd.config[:login], CloudCrowd.config[:password]] if CloudCrowd.config[:use_http_authentication] + @central_server = RestClient::Resource.new(*params) + end # Return the readable status name of an internal CloudCrowd status number. def display_status(status) DISPLAY_STATUS_MAP[status] end # Some workers might not ever need to load all the installed actions, # so we lazy-load them. Think about a variant of this for installing and # loading actions into a running CloudCrowd cluster on the fly. def actions(name) - action_class = name.camelize + action_class = Inflector.camelize(name) begin raise NameError, "can't find the #{action_class} Action" unless Module.constants.include?(action_class) Module.const_get(action_class) rescue NameError => e user_action = "#{@config_path}/actions/#{name}" - default_action = "#{CloudCrowd::ROOT}/actions/#{name}" + default_action = "#{ROOT}/actions/#{name}" require user_action and retry if File.exists? "#{user_action}.rb" require default_action and retry if File.exists? "#{default_action}.rb" raise e end end \ No newline at end of file