Fixes #5579: Implement heartbeat mode

Same as above, please avoid duplication like this and refactor this.

Also, about class naming: it took me a long time to figure out what these new classes were about. Since the message are named "StartRun" and "EndRun", let's please use them in the class names. So can you use "endrun_heartbeat_sent" and "startrun_heartbeat_sent".