# The Grand Central of code loading... $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) # Common Gems: require 'rubygems' gem 'activerecord' gem 'daemons' gem 'json' gem 'rest-client' gem 'right_aws' gem 'sinatra' # Autoloading for all the pieces which may or may not be needed: autoload :ActiveRecord, 'activerecord' autoload :Benchmark, 'benchmark' autoload :Daemons, 'daemons' autoload :Digest, 'digest' autoload :ERB, 'erb' autoload :FileUtils, 'fileutils' autoload :JSON, 'json' autoload :RestClient, 'rest_client' autoload :RightAws, 'right_aws' autoload :Sinatra, 'sinatra' autoload :Socket, 'socket' autoload :YAML, 'yaml' module CloudCrowd # 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.5' # 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. SUCCEEDED = 2 # A Job has failed if even a single one of its WorkUnits has failed (they may # be attempted multiple times on failure, however). FAILED = 3 # A Job is splitting if it's in the process of dividing its inputs up into # multiple WorkUnits. SPLITTING = 4 # A Job is merging if it's busy collecting all of its successful WorkUnits # back together into the final result. MERGING = 5 # A work unit is considered to be complete if it succeeded or if it failed. COMPLETE = [SUCCEEDED, FAILED] # A work unit is considered incomplete if it's being processed, split up or # merged together. INCOMPLETE = [PROCESSING, SPLITTING, MERGING] # Mapping of statuses to their display strings. DISPLAY_STATUS_MAP = { 1 => 'processing', 2 => 'succeeded', 3 => 'failed', 4 => 'splitting', 5 => 'merging' } class << self attr_reader :config # Configure CloudCrowd by passing in the path to config.yml. def configure(config_path) @config_path = File.expand_path(File.dirname(config_path)) @config = YAML.load_file(config_path) end # Configure the CloudCrowd central database (and connect to it), by passing # in a path to database.yml. The file should use the standard # ActiveRecord connection format. def configure_database(config_path) configuration = YAML.load_file(config_path) ActiveRecord::Base.establish_connection(configuration) end # Get a reference to the central server, including authentication, # if configured. 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 displayable status name of an internal CloudCrowd status number. # (See the above constants). def display_status(status) DISPLAY_STATUS_MAP[status] end # CloudCrowd::Actions are requested dynamically by name. Access them through # this actions property, which behaves like a hash. At load time, we # load all installed Actions and CloudCrowd's default Actions into it. # If you wish to have certain workers be specialized to only handle certain # Actions, then install only those into the actions directory. def actions return @actions if @actions @actions = {} default_actions = Dir["#{ROOT}/actions/*.rb"] custom_actions = Dir["#{CloudCrowd.config[:actions_path]}/*.rb"] || Dir["#{@config_path}/actions/*.rb"] (default_actions + custom_actions).each do |path| name = File.basename(path, File.extname(path)) require path @actions[name] = Module.const_get(Inflector.camelize(name)) end @actions end end end