lib/rocket_job/plugins/document.rb in rocketjob-2.0.0 vs lib/rocket_job/plugins/document.rb in rocketjob-2.1.1
- old
+ new
@@ -6,24 +6,22 @@
module RocketJob
module Plugins
# Base class for storing models in MongoDB
module Document
- autoload :Static, 'rocket_job/plugins/document/static'
-
extend ActiveSupport::Concern
include MongoMapper::Document
- include RocketJob::Plugins::Document::Static
included do
- # Add after_initialize & after_find callbacks
- define_model_callbacks :initialize, :find, :only => [:after]
-
- # Prevent data in MongoDB from re-defining the model behavior
+ # Prevent data in MongoDB from re-defining the model behavior.
self.static_keys = true
- # Turn off embedded callbacks. Slow and not used for Jobs
+ # Only save changes to this instance to prevent losing
+ # changes made by other processes or threads.
+ self.partial_updates = true
+
+ # Turn off embedded callbacks. Slow and not used by Jobs.
embedded_callbacks_off
end
# Patch the way MongoMapper reloads a model
def reload
@@ -33,24 +31,9 @@
initialize_default_values
load_from_database(doc)
self
else
raise MongoMapper::DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
- end
- end
-
- # Add after_initialize callbacks
- # TODO: Remove after new MongoMapper gem is released
- # Also remove define_model_callbacks above
- def initialize(*)
- run_callbacks(:initialize) { super }
- end
-
- def initialize_from_database(*)
- run_callbacks(:initialize) do
- run_callbacks(:find) do
- super
- end
end
end
private