lib/eco/api/session/batch/job.rb in eco-helpers-2.0.41 vs lib/eco/api/session/batch/job.rb in eco-helpers-2.0.42
- old
+ new
@@ -233,12 +233,26 @@
else
feedback.as_update(data, *args)
end
end
+ # Method to generate the base of people that will be present in the queue
+ # @note
+ # - If the entry is a new person, we are not in a creation job and the person doesn't have `id`
+ # it means that it failed to be created (it doesn't exist on server-side).
+ # The entry won't be included.
+ # - The contingency above wouldn't be necessary if the server worked perfectly.
def processed_queue
- @queue.each {|e| @callbacks[e].call(e) if @callbacks.key?(e) }
- apply_policies(api_included(@queue)).select do |e|
+ pre_filtered = @queue.select do |entry|
+ if unexisting = entry.new? && !entry.id && type != :create
+ ref = Eco::API::Session::Batch::Feedback.person_ref(entry)
+ msg = "Job ('#{name}':#{type}): excluded unexisting entry (failed creation): #{ref}"
+ session.logger.warn(msg)
+ end
+ !unexisting
+ end
+ pre_filtered.each {|e| @callbacks[e].call(e) if @callbacks.key?(e) }
+ apply_policies(api_included(pre_filtered)).select do |e|
!as_update(e).empty?
end.select do |e|
next true unless e.is_a?(Ecoportal::API::V1::Person)
next true unless e.new?
# new people should either have account or details