code: def execute_task_local(self, record_id, history_id=None):
      record = db.Jobs.query.get(record_id)
  
      # set up environment
  
      ctx.set_default()
      ctx.company_id = record.company_id
      if record.user_class is not None:
          ctx.user_class = record.user_class
  
      query_context_controller.set_context("job", record.id)
      if history_id is None:
          history_record = db.JobsHistory(
              job_id=record.id,
              start_at=dt.datetime.now(),
              company_id=record.company_id,
          )
          db.session.add(history_record)
          db.session.flush()
          history_id = history_record.id
          db.session.commit()
  
      else:
          history_record = db.JobsHistory.query.get(history_id)
  
      error = ""
  
      project_controller = ProjectController()
      project = project_controller.get(record.project_id)
      executed_sql = ""
      for sql in split_sql(record.query_str):
          try:
              #  fill template variables
              if "{{PREVIOUS_START_DATETIME}}" in sql:
                  # get previous run date
                  history_prev = (
                      db.session.query(db.JobsHistory.start_at)
                      .filter(
                          db.JobsHistory.job_id == record.id,
                          db.JobsHistory.id != history_id,
                      )
                      .order_by(db.JobsHistory.id.desc())
                      .first()
                  )
                  if history_prev is None:
                      # start date of the job
                      value = record.created_at
                  else:
                      # fix for twitter: created_at filter must be minimum of 10 seconds prior to the current time
                      value = history_prev.start_at - dt.timedelta(
                          seconds=60
                      )
                  value = value.strftime("%Y-%m-%d %H:%M:%S")
                  sql = sql.replace(
                      "{{PREVIOUS_START_DATETIME}}", value
                  )
  
              if "{{START_DATE}}" in sql:
                  value = history_record.start_at.strftime("%Y-%m-%d")
                  sql = sql.replace("{{START_DATE}}", value)
              if "{{START_DATETIME}}" in sql:
                  value = history_record.start_at.strftime(
                      "%Y-%m-%d %H:%M:%S"
                  )
                  sql = sql.replace("{{START_DATETIME}}", value)
              query = parse_sql(sql, dialect="mindsdb")
  
              from mindsdb.api.executor.controllers.session_controller import (
                  SessionController,
              )
              from mindsdb.api.executor.command_executor import (
                  ExecuteCommands,
              )
  
              sql_session = SessionController()
              sql_session.database = project.name
  
              command_executor = ExecuteCommands(sql_session)
  
              executed_sql += sql + "; "
  
              ret = command_executor.execute_command(query)
              if ret.error_code is not None:
                  error = ret.error_message
                  break
          except Exception as e:
              logger.error(e)
              error = str(e)
              break
  
      try:
          self.update_task_schedule(record)
      except Exception as e:
          db.session.rollback()
          logger.error(f"Error to update schedule: {e}")
          error += f"Error to update schedule: {e}"
  
          # stop scheduling
          record.next_run_at = None
  
      history_record = db.JobsHistory.query.get(history_id)
  
      if error:
          history_record.error = error
      history_record.end_at = dt.datetime.now()
      history_record.query_str = executed_sql
  
      db.session.commit()
  
imports: import re
  import datetime
  from dateutil.relativedelta import relativedelta
  import sqlalchemy
  from mindsdb_sql import parse_sql, ParsingException
  from mindsdb.utilities.context import context
  from mindsdb.utilities.exception import EntityNotExistsError, EntityExistsError
  from mindsdb.interfaces.storage import db
  from mindsdb.interfaces.database.projects import ProjectController
  from mindsdb.interfaces.query_context.context_controller import query_context_controller
  from mindsdb.utilities import log
label_desc: Use image node_id 5 for calling the JobsExecutor obj's underlying member method code with example usage: obj.execute_task_local(record_id, history_id) without return types