lib/rocket_job/sliced/slices.rb in rocketjob-5.1.1 vs lib/rocket_job/sliced/slices.rb in rocketjob-5.2.0.beta1
- old
+ new
@@ -79,23 +79,24 @@
slice.first_record_number = input_slice.first_record_number
end
begin
slice.save!
- rescue Mongo::Error::OperationFailure => exc
+ rescue Mongo::Error::OperationFailure => e
# Ignore duplicates since it means the job was restarted
- raise(exc) unless exc.message.include?('E11000')
+ raise(e) unless e.message.include?("E11000")
+
logger.warn "Skipped already processed slice# #{slice.id}"
end
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' }
+ 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)
end
# Forward additional methods.
@@ -122,17 +123,19 @@
def running
all.running
end
# Mongoid does not apply ordering, add sort
+ # rubocop:disable Style/RedundantSort
def first
- all.sort('_id' => 1).first
+ all.sort("_id" => 1).first
end
def last
- all.sort('_id' => -1).first
+ 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.
#
# Each struct consists of:
@@ -147,22 +150,22 @@
def group_exceptions
result_struct = Struct.new(:class_name, :count, :messages)
result = all.collection.aggregate(
[
{
- '$match' => {state: 'failed'}
+ "$match" => {state: "failed"}
},
{
- '$group' => {
- _id: {error_class: '$exception.class_name'},
- messages: {'$addToSet' => '$exception.message'},
- count: {'$sum' => 1}
+ "$group" => {
+ _id: {error_class: "$exception.class_name"},
+ messages: {"$addToSet" => "$exception.message"},
+ count: {"$sum" => 1}
}
}
]
)
result.collect do |errors|
- result_struct.new(errors['_id']['error_class'], errors['count'], errors['messages'])
+ result_struct.new(errors["_id"]["error_class"], errors["count"], errors["messages"])
end
end
end
end
end