$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) # Common Gems: require 'json' require 'rest_client' require 'right_aws' # Common CloudCrowd libs: require 'cloud_crowd/core_ext' require 'cloud_crowd/action' module CloudCrowd # Root directory of the CloudCrowd gem. ROOT = File.expand_path(File.dirname(__FILE__) + '/..') # Keep the version in sync with the gemspec. VERSION = '0.0.2' # 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+. def configure_database(config_path) configuration = YAML.load_file(config_path) ActiveRecord::Base.establish_connection(configuration) 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 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}" 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 end end