A small service collects the results of batch notification sending through the dispatch method. After a recent refactor, the delivery report started behaving unstably: when a failure occurs inside the user handler, the final list of statuses can look successful, and the attempt log sometimes contains entries for items that were not actually sent.
NotificationBatch#dispatch accepts an array of hashes with keys :id and :payload.{ id: ..., status: :sent } to the result."failed:<id>" to the log;NotificationBatch#dispatch.irb or in a separate file:log = []
batch = NotificationBatch.new(log: log)
begin
batch.dispatch([
{ id: "n-1", payload: "ok" },
{ id: "n-2", payload: "boom" }
]) do |notification|
raise "delivery failed" if notification[:payload] == "boom"
end
rescue => e
puts e.message
end
p log
log and to what behavior is visible when the block raises.3.3ruby notification_batch.rb or via irbdispatch input: Array<Hash> with keys :id, :payloadUse line comments to explain the problem, its impact, the fix and how to test it.