BrightcoveOS/Diamond — pull request #139 by phobos182 (2012-09-05 21:24:51+00:00)
Title: Handler flush logic.

Use Case:
When batching requests to save on RPC calls to a remote system, the pattern used is to append metrics to an array. Once the array meets the batch size, send the request. Issues arise when the collector script terminates there may be items still in the array that have not been sent because they have not reached the batch size.

To resolve this, I have added a finally method to the collector run to invoke 'flush()' on each handler once a collector script has finished it's run. I have also added a default 'flush()' method on the Handler base class that can be overridden by the subclasses. I catch the exception if the class is not overridden, and continue gracefully. Therefore handlers can choose to use the flush logic in their class.