lib/rocket_job/sliced/slices.rb in rocketjob-5.4.1 vs lib/rocket_job/sliced/slices.rb in rocketjob-6.0.0.rc1

- old
+ new

@@ -48,12 +48,12 @@ 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 - all.sort(id: 1).each { |document| yield(document) } + def each(&block) + all.sort(id: 1).each(&block) end # Insert a new slice into the collection # # Returns [Integer] the number of records uploaded @@ -94,10 +94,21 @@ logger.warn "Skipped already processed slice# #{slice.id}" end slice 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 + + extra_records = slice.is_a?(Slice) ? slice.records : slice + existing_slice.records = existing_slice.records + extra_records + existing_slice.save! + existing_slice + end + 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" } @@ -137,9 +148,10 @@ end def last all.sort("_id" => -1).first end + # rubocop:enable Style/RedundantSort # Returns [Array<Struct>] grouped exceptions by class name, # and unique exception messages by exception class. #