Refactor heartbeat to delegate to the modulestores and sql
LMS-2801