<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run(self):
 """Runs the thread This method handles sending the heartbeat to the Discord websocket server, so the connection can remain open and the bot remain online for those commands that require it to be. Args: None """

        while self.should_run:
            try:
                self.logger.debug('Sending heartbeat, seq ' + last_sequence)
                self.ws.send(json.dumps({
                    'op': 1,
                    'd': last_sequence
                }))
            except Exception as e:
                self.logger.error(f'Got error in heartbeat: {str(e)}')
            finally:
                elapsed = 0.0
                while elapsed < self.interval and self.should_run:
                    time.sleep(self.TICK_INTERVAL)
                    elapsed += self.TICK_INTERVAL