feat(cb): use context manager in `generate_batch` (#42190)
* feat(cb): use context manager in `generate_batch`
* refactor(cb): group `with` stmts
* refactor(cb): move log line before `stop` call
Co-authored-by: Rémi Ouazan <83456801+remi-or@users.noreply.github.com>
* fix: lint
---------
Co-authored-by: Rémi Ouazan <83456801+remi-or@users.noreply.github.com>