Class: MongoMapperParallel::Key
- Inherits:
-
Object
- Object
- MongoMapperParallel::Key
- Defined in:
- lib/mongo_mapper_parallel.rb
Instance Attribute Summary collapse
-
#compiler ⇒ Object
readonly
Returns the value of attribute compiler.
-
#completed ⇒ Object
Returns the value of attribute completed.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#future_key ⇒ Object
A chunk that will be parallelized.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#args ⇒ Array, Hash
The arguments to pass to the Javascript function to run on the resources.
-
#command_class ⇒ Class
The Ruby Class representing the collection containing the resources.
-
#compile ⇒ Object
Sends the Javascript function, the range, and the arguments to the MongoDB instance for computation via the
db.runCommandcommand. -
#initialize(opts = {}) ⇒ Key
constructor
A chunk that will be parallelized.
-
#javascript ⇒ String
The javascript function to run on the resources.
Constructor Details
#initialize(opts = {}) ⇒ Key
A chunk that will be parallelized
38 39 40 41 42 43 44 45 |
# File 'lib/mongo_mapper_parallel.rb', line 38 def initialize(opts={}) @key = opts[:key] @compiler = opts[:compiler] @position = opts[:position] @future_key = opts[:future_key] @completed = false @debug = opts[:debug].nil? ? true : opts[:debug] end |
Instance Attribute Details
#compiler ⇒ Object (readonly)
Returns the value of attribute compiler.
28 29 30 |
# File 'lib/mongo_mapper_parallel.rb', line 28 def compiler @compiler end |
#completed ⇒ Object
Returns the value of attribute completed.
27 28 29 |
# File 'lib/mongo_mapper_parallel.rb', line 27 def completed @completed end |
#debug ⇒ Object
Returns the value of attribute debug.
29 30 31 |
# File 'lib/mongo_mapper_parallel.rb', line 29 def debug @debug end |
#future_key ⇒ Object
A chunk that will be parallelized
25 26 27 |
# File 'lib/mongo_mapper_parallel.rb', line 25 def future_key @future_key end |
#key ⇒ Object
Returns the value of attribute key.
26 27 28 |
# File 'lib/mongo_mapper_parallel.rb', line 26 def key @key end |
Instance Method Details
#args ⇒ Array, Hash
The arguments to pass to the Javascript function to run on the resources
56 |
# File 'lib/mongo_mapper_parallel.rb', line 56 def args; @compiler.args; end |
#command_class ⇒ Class
The Ruby Class representing the collection containing the resources
61 |
# File 'lib/mongo_mapper_parallel.rb', line 61 def command_class; @compiler.command_class; end |
#compile ⇒ Object
Sends the Javascript function, the range, and the arguments to the MongoDB instance for computation via the db.runCommand command.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mongo_mapper_parallel.rb', line 65 def compile search_opts = {:name => {:$gte => @key}} if @future_key then search_opts[:name][:$lte] = @future_key end begin command_class.database.command({ :"$eval" => javascript, :args => [@key, @future_key, args], :nolock => true }) rescue Mongo::ConnectionFailure raise Mongo::ConnectionFailure.new "Connection disconnected at position #{@position}" end @completed = true puts "Completed chunk (#{@position})".green if @debug end |
#javascript ⇒ String
The javascript function to run on the resources
50 |
# File 'lib/mongo_mapper_parallel.rb', line 50 def javascript; @compiler.javascript; end |