I extracted an ActiveJob batching utility from AngryBuilding

https://github.com/RStankov/AngryBatch

@rstankov That looks very useful, I remember needing something like this in the past.

One thing I'm wondering is how granular error handling should be. Right now, I see that the success handler is triggered if all the jobs succeed (https://github.com/RStankov/AngryBatch/blob/main/lib/angry_batch/batch.rb#L49-L57), but I feel like you'd want to know which failed and which succeeded. Like, maybe a "success" handler for all succeeding, "failure" for some failing, and "complete" with lists of succeding and failing jobs?

AngryBatch/lib/angry_batch/batch.rb at main · RStankov/AngryBatch

ActiveJob batch processing with completion hooks. Contribute to RStankov/AngryBatch development by creating an account on GitHub.

GitHub

@AndrewRadev

I'm open to suggestions for better error handling.

I tried a couple of approaches, but I didn't like any of them.

Thus, I left with the simplest one, which will allow me to add more granular ones later.

@rstankov Yeah, it's a very tricky problem, because it's very situational, depends on the use case. As you say, probably best to keep it simple and increase flexibility later.

@AndrewRadev With my current usage of AngryBatch, I haven't encountered many issues with the current error handling approach.

Most of the enqueue jobs failed due to network issues, but after a couple of retries, they completed.