lib/cloud-crowd.rb in documentcloud-cloud-crowd-0.1.1 vs lib/cloud-crowd.rb in documentcloud-cloud-crowd-0.2.0
- old
+ new
@@ -28,11 +28,11 @@
# Common code which should really be required in every circumstance.
require 'cloud_crowd/exceptions'
module CloudCrowd
- # Autoload all the CloudCrowd classes which may not be required.
+ # Autoload all the CloudCrowd internals.
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'
@@ -40,40 +40,42 @@
autoload :NodeRecord, 'cloud_crowd/models'
autoload :Server, 'cloud_crowd/server'
autoload :Worker, 'cloud_crowd/worker'
autoload :WorkUnit, 'cloud_crowd/models'
- # Root directory of the CloudCrowd gem.
- ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
+ # Keep this version in sync with the gemspec.
+ VERSION = '0.2.0'
- # Keep the version in sync with the gemspec.
- VERSION = '0.1.1'
+ # Increment the schema version when there's a backwards incompatible change.
+ SCHEMA_VERSION = 2
+
+ # Root directory of the CloudCrowd gem.
+ ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
- # A Job is processing if its WorkUnits in the queue to be handled by workers.
- PROCESSING = 1
+ # A Job is processing if its WorkUnits are in the queue to be handled by nodes.
+ PROCESSING = 1
# A Job has succeeded if all of its WorkUnits have finished successfully.
- SUCCEEDED = 2
+ 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
+ FAILED = 3
# A Job is splitting if it's in the process of dividing its inputs up into
# multiple WorkUnits.
- SPLITTING = 4
+ SPLITTING = 4
# A Job is merging if it's busy collecting all of its successful WorkUnits
# back together into the final result.
- MERGING = 5
+ MERGING = 5
- # A work unit is considered to be complete if it succeeded or if it failed.
- COMPLETE = [SUCCEEDED, FAILED]
+ # A Job 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]
+ # A Job is considered incomplete if it's being processed, split up or merged.
+ INCOMPLETE = [PROCESSING, SPLITTING, MERGING]
# Mapping of statuses to their display strings.
DISPLAY_STATUS_MAP = ['unknown', 'processing', 'succeeded', 'failed', 'splitting', 'merging']
class << self
@@ -86,33 +88,49 @@
end
# Configure the CloudCrowd central database (and connect to it), by passing
# in a path to <tt>database.yml</tt>. The file should use the standard
# ActiveRecord connection format.
- def configure_database(config_path)
+ def configure_database(config_path, validate_schema=true)
configuration = YAML.load_file(config_path)
ActiveRecord::Base.establish_connection(configuration)
+ if validate_schema
+ version = ActiveRecord::Base.connection.select_values('select max(version) from schema_migrations').first.to_i
+ return true if version == SCHEMA_VERSION
+ puts "Your database schema is out of date. Please use `crowd load_schema` to update it. This will wipe all the tables, so make sure that your jobs have a chance to finish first.\nexiting..."
+ exit
+ end
end
- # Get a reference to the central server, including authentication,
- # if configured.
+ # 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)
+ @central_server ||= RestClient::Resource.new(CloudCrowd.config[:central_server], CloudCrowd.client_options)
end
+
+ # The standard RestClient options for the central server talking to nodes,
+ # as well as the other way around. There's a timeout of 5 seconds to open
+ # a connection, and a timeout of 30 to finish reading it.
+ def client_options
+ return @client_options if @client_options
+ @client_options = {:timeout => 30, :open_timeout => 5}
+ if CloudCrowd.config[:http_authentication]
+ @client_options[:user] = CloudCrowd.config[:login]
+ @client_options[:password] = CloudCrowd.config[:password]
+ end
+ @client_options
+ end
# Return the displayable status name of an internal CloudCrowd status number.
# (See the above constants).
def display_status(status)
DISPLAY_STATUS_MAP[status] || 'unknown'
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
+ # If you wish to have certain nodes 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"]
\ No newline at end of file