lib/rocket_job/sliced/slices.rb in rocketjob-6.0.0.rc3 vs lib/rocket_job/sliced/slices.rb in rocketjob-6.0.0
- old
+ new
@@ -40,16 +40,10 @@
slice = new(params)
slice.save!
slice
end
- # Returns whether this collection contains specialized binary slices for creating binary data from each slice
- # that is then just downloaded as-is into output files.
- def binary?
- slice_class.binary?
- end
-
# Returns output slices in the order of their id
# which is usually the order in which they were written.
def each(&block)
all.sort(id: 1).each(&block)
end
@@ -94,10 +88,15 @@
logger.warn "Skipped already processed slice# #{slice.id}"
end
slice
end
+ def insert_many(slices)
+ documents = slices.collect(&:as_document)
+ all.collection.insert_many(documents)
+ end
+
# Append to an existing slice if already present
def append(slice, input_slice)
existing_slice = all.where(id: input_slice.id).first
return insert(slice, input_slice) unless existing_slice
@@ -109,12 +108,16 @@
alias << insert
# Index for find_and_modify only if it is not already present
def create_indexes
- all.collection.indexes.create_one(state: 1, _id: 1) if all.collection.indexes.none? { |i| i["name"] == "state_1__id_1" }
- rescue Mongo::Error::OperationFailure
- all.collection.indexes.create_one(state: 1, _id: 1)
+ missing =
+ begin
+ all.collection.indexes.none? { |i| i["name"] == "state_1__id_1" }
+ rescue Mongo::Error::OperationFailure
+ true
+ end
+ all.collection.indexes.create_one({state: 1, _id: 1}, unique: true) if missing
end
# Forward additional methods.
def_instance_delegators :@all, :collection, :count, :delete_all, :first, :find, :last, :nor, :not, :or, :to_a, :where