lib/rocket_job/config.rb in rocketjob-1.3.0 vs lib/rocket_job/config.rb in rocketjob-2.0.0.rc1
- old
+ new
@@ -1,14 +1,11 @@
# encoding: UTF-8
module RocketJob
# Centralized Configuration for Rocket Jobs
class Config
- include MongoMapper::Document
+ include Plugins::Document
- # Prevent data in MongoDB from re-defining the model behavior
- #self.static_keys = true
-
# Returns the single instance of the Rocket Job Configuration for this site
# in a thread-safe way
def self.instance
@@instance ||= begin
first || create
@@ -16,11 +13,12 @@
# In case another process has already created the first document
first
end
end
- # By enabling inline_mode jobs will be called in-line
+ # Useful for Testing, not recommended elsewhere
+ # By enabling inline_mode jobs will be called in-line using perform_now
# No worker processes will be created, nor threads created
cattr_accessor(:inline_mode) { false }
# @formatter:off
# The maximum number of worker threads to create on any one worker
@@ -41,13 +39,10 @@
#
# Note:
# Not all job types support pausing in the middle
key :re_check_seconds, Integer, default: 60
- # Limit the number of workers per job class per worker
- # 'class_name' / group => 100
- #key :limits, Hash
# @formatter:on
# Replace the MongoMapper default mongo connection for holding jobs
def self.mongo_connection=(connection)
connection(connection)
@@ -62,25 +57,28 @@
Job.set_database_name(db_name)
Config.set_database_name(db_name)
DirmonEntry.set_database_name(db_name)
end
- # Use a separate Mongo connection for the Records and Results
- # Allows the records and results to be stored in a separate Mongo database
- # from the Jobs themselves.
- #
- # It is recommended to set the work_connection to a local Mongo Worker that
- # is not replicated to another data center to prevent flooding the network
- # with replication of data records and results.
- # The jobs themselves can/should be replicated across data centers so that
- # they are never lost.
- def self.mongo_work_connection=(connection)
- @@mongo_work_connection = connection
- end
+ # Configure MongoMapper
+ def self.load!(environment='development', file_name=nil, encryption_file_name=nil)
+ config_file = file_name ? Pathname.new(file_name) : Pathname.pwd.join('config/mongo.yml')
+ if config_file.file?
+ logger.debug "Reading MongoDB configuration from: #{config_file}"
+ config = YAML.load(ERB.new(config_file.read).result)
+ MongoMapper.setup(config, environment)
+ else
+ raise(ArgumentError, "Mongo Configuration file: #{config_file.to_s} not found")
+ end
- # Returns the Mongo connection for the Records and Results
- def self.mongo_work_connection
- @@mongo_work_connection || connection
+ # Load Encryption configuration file if present
+ if defined?(SymmetricEncryption)
+ config_file = encryption_file_name ? Pathname.new(encryption_file_name) : Pathname.pwd.join('config/symmetric-encryption.yml')
+ if config_file.file?
+ logger.debug "Reading SymmetricEncryption configuration from: #{config_file}"
+ SymmetricEncryption.load!(config_file.to_s, environment)
+ end
+ end
end
end
end