Add on_cleanup event to pipeline.

(cherry picked from commit 202dfe470625cff72f8a68d5dabf2c0351c24751)