code: def check_tasks(self):
      allowed_tasks = set()
  
      for task in db.session.query(db.Tasks).filter(
          db.Tasks.active == True
      ):  # noqa
          allowed_tasks.add(task.id)
  
          # start new tasks
          if task.id not in self._active_tasks:
              self.start_task(task)
  
      # Check active tasks
      active_tasks = list(self._active_tasks.items())
      for task_id, task in active_tasks:
          if task_id not in allowed_tasks:
              # old task
              self.stop_task(task_id)
  
          elif not task.is_alive():
              # dead task
              self.stop_task(task_id)
  
          else:
              # need to be reloaded ?
              record = db.Tasks.query.get(task_id)
              if record.reload:
                  record.reload = False
                  self.stop_task(task_id)
              else:
                  # set alive time of running tasks
                  self._set_alive(task_id)
  
file_path: mindsdb/mindsdb/interfaces/tasks/task_monitor.py
imports: import datetime
  import os
  import socket
  import time
  import sqlalchemy
  from mindsdb.interfaces.storage import db
  from mindsdb.utilities import log
  from mindsdb.utilities.config import Config
  from .task_thread import TaskThread
label_desc: Use image node_id 4 for calling the TaskMonitor obj's underlying member method code with example usage: obj.check_tasks() without return types